public void AsyncCallTestLogin(IAsyncResult res) { try { btnLogin.BeginInvoke(new Action(() => { btnLogin.Enabled = true; })); WebReference.WebSDataBrCode BrServer = res.AsyncState as WebReference.WebSDataBrCode; bool result = BrServer.EndTest_Login(res); if (result) { FStart = new StartMenu(CBrHeader.Login, CBrHeader.Password, Date, Smena); FStart.ShowDialog(); } else { MessageBox.Show("Введите правильный логин или пароль"); } } catch (Exception ex) { MessageBox.Show("Ошибка подключения к серверу или другая ошибка"); CLog.WriteException("MainWindows.cs", "AsyncCallTestLogin", ex.ToString()); } finally { btnLogin.BeginInvoke(new Action(() => { btnLogin.Enabled = true; })); } }