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);