Example #1
0
 private void cmdConnect_Click(object sender, EventArgs e)
 {
     Codes.CenterSetting setting = new Codes.CenterSetting();
     setting.Host = txtAddress.Text;
     setting.Port = int.Parse(txtPort.Text);
     Codes.ManagerSetting.SaveCenterSetting(setting);
     mClient.Connect(txtAddress.Text, int.Parse(txtPort.Text));
     cmdNew.Enabled = cmdDisconnect.Enabled = !(cmdConnect.Enabled = !mClient.NetClient.Connected);
     if (!mClient.NetClient.Connected)
     {
         txtStatus.Text = mClient.NetClient.LastError.Message;
     }
     else
     {
         mClient.List();
     }
 }
Example #2
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            // Register callback for application stopping event. App shutdown
            // will be delayed until this callback is finished.
            appLifetime.ApplicationStopping.Register(() =>
            {
                if (Connection != null)
                {
                    logger.LogInformation("Stopping battle host.");
                    Connection.RequestStream.CompleteAsync().Wait();
                }
            });

            Connection = client.Connect(cancellationToken: cancellationToken);

            // Start background task handling incoming battle requests.
            Task.Run(async() =>
            {
                connection.Connect(Connection.RequestStream);

                try
                {
                    await foreach (var item in Connection.ResponseStream.ReadAllAsync(CancellationToken.None))
                    {
                        connection.Handle(item);
                    }
                }
                finally
                {
                    // When connection to manager stops, the application should stop.
                    appLifetime.StopApplication();
                }
            }, CancellationToken.None);

            return(Task.CompletedTask);
        }