调用WCF的异步方法

            AsyncCallback aLoginCallback = delegate(IAsyncResult result)
                                           {
                                               var aSystemUser = WcfClient.Instance.EndSystemUser_Login(result);
                                               result.AsyncWaitHandle.Close();

                                               if (string.IsNullOrWhiteSpace(aSystemUser.UserId))
                                               {
                                                   ShowMessageBoxInNonMainThread("登录失败:用户名称或者用户密码错误!");
                                                   return;
                                               }

                                               CommonCache.CurrentUser = aSystemUser;

                                               //SynchronizationContext和SendOrPostCallback的引入是为了解决不能在非主线程中访问主线程中创建的控件的问题
                                               SendOrPostCallback aSendOrPostCallback = delegate
                                                                                        {
                                                                                            Hide();
                                                                                            MainForm.Instance.ShowDialog();
                                                                                        };
                                               SynchronizationContext.Current.Send(aSendOrPostCallback, null);
                                           };

            var aParam = GetForm<SystemUserParameter>();
            WcfClient.Instance.BeginSystemUser_Login(aParam, aLoginCallback, null);

  

原文地址:https://www.cnblogs.com/ningkyolei/p/4548286.html