Пример #1
0
 private async void connectButton_Click(object sender, EventArgs e)
 {
     _gameData.PlayerName = nameTextBox.Text;
     try
     {
         connectButton.Enabled = !connectButton.Enabled;
         if (connectButton.Text == "Connect")
         {
             await Task.Factory.StartNew(() =>
             {
                 _server = _channelFactory.CreateChannel();
                 _server.ConnectToServer(_gameData.PlayerName);
                 //this.Text = $"Tic Tac Toe, [{nameTextBox.Text}]";
                 this.Text = string.Format("Tic Tac Toe, [{0}]", nameTextBox.Text);
                 isConnected = true;
             });
         }
         else
             _server.StopGame();
         nameTextBox.Visible = false;
         connectButton.Text = connectButton.Text == "Connect" ? "Disconnect" : "Connect";
         connectButton.Enabled = !connectButton.Enabled;
     }
     catch (Exception)
     {
         infoLabel.Text = (_message_UnableToConnect);
         connectButton.Enabled = !connectButton.Enabled;
         isConnected = false;
         connectButton.Text = "Connect";
     }
 }