Beispiel #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (btnConnect.Text == "Connect")
            {
                SaveImage.StartSaveToFile();

                try
                {
                    tcpConnection               = new TcpConnection(tbIp.Text, tbPort.Text);
                    tcpConnection.ShowMessage  += ConsoleMessage;
                    tcpConnection.DataReceived += TcpConnection_DataReceived;
                    tcpConnection.StartReceiveData();
                }
                catch (Exception ex)
                {
                    ConsoleMessage(ex.Message);

                    return;
                }

                btnConnect.Text = "Disconnect";
                tbIp.Enabled    = false;
                tbPort.Enabled  = false;
            }
            else
            {
                tcpConnection.StopReceiveData();
                tcpConnection = null;

                btnConnect.Text = "Connect";
                tbIp.Enabled    = true;
                tbPort.Enabled  = true;
            }
        }
Beispiel #2
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            tcpConnection?.StopReceiveData();

            SaveImage.StopSaveToFile();
        }