异步延迟问题
操作就是点击预览之后返回一个字符串,然后页面根据这个字符串来操作
但因为异步方法,所以会有延迟,返回的字符串总是空
求教怎么解决?
我看有个帖子说可以加个延迟System.Threading.Thread.Sleep(1000);
可是我不知道这个延迟应该加在哪?
这是页面的代码,点击预览执行方法
//预览//.sfvm是viewmodel层this._sfvm.AsynchronousMessage += new EventHandler<HandMessage>(_sfvm_AsynchronousMessage);private void btnView_Click(object sender, RoutedEventArgs e){ FaxInfo fax = modelToFaxInfo(this._sfvm.FaxModel); this._sfvm.getFaxTifFileUri(fax);}void _sfvm_AsynchronousMessage(object sender, HandMessage e){ if (!string.IsNullOrEmpty(e.Result)) { sourseUrl = e.Result; } else { messageBox = new cwMessageBox("无法生成预览"); messageBox.Show(); }}
public void getFaxTifFileUri(FaxInfo fax, CustomException ex){ FaxServiceProxy.FaxServiceClient proxy = new FaxServiceClient(); proxy.GetFaxTifFileUriCompleted += new EventHandler<GetFaxTifFileUriCompletedEventArgs>(proxy_GetFaxTifFileUriCompleted); proxy.GetFaxTifFileUriAsync(fax, ex);}void proxy_GetFaxTifFileUriCompleted(object sender, GetFaxTifFileUriCompletedEventArgs e){ if (e.Error==null) { HandMessage hm = new HandMessage(); hm.Result = e.Result; AsynchronousMessage(null, hm); }}/// <summary> 回调事件/// </summary>public event EventHandler<HandMessage> AsynchronousMessage;