private DClient Conection(string host, int port, string login, string password) { this.Dispatcher.Invoke(delegate() { btnLogin.IsEnabled = false; prgStatus.Visibility = Visibility.Visible; }); DClient cl = new DClient(host, port); try { if (!cl.InitConnection()) { MessageBox.Show("Не удалось соединиться с сервером"); return(null); } cl.SignIn(login, password); } catch (Exception ex) { MessageBox.Show(ex.Message); return(cl); } return(cl); }