예제 #1
0
        private void BtnToggleClick(object sender, EventArgs e)
        {
            if (Worker != null)
            {
                try
                {
                    WorkerAbort.Cancel();
                    Worker.Wait(100);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message);
                }
                ReflectDisconnection();
                return;
            }
            if (!CommonBehavior.VerifyEndpoint(TbIp, TbPort, out IPEndPoint addr))
            {
                return;
            }

            WorkerAbort = new CancellationTokenSource();
            Worker      = new Task(new Action(() => TcpWorker(addr)), WorkerAbort.Token);
            Worker.Start();
            BtnToggle.Text = "Connecting...";
        }
예제 #2
0
        private void StartServer()
        {
            if (!CommonBehavior.VerifyPath(TbPath))
            {
                return;
            }
            if (!CommonBehavior.VerifyEndpoint(TbIp, TbPort, out IPEndPoint addr))
            {
                return;
            }

            TbIp.ReadOnly = TbPort.ReadOnly = TbPath.ReadOnly = true;
            WorkerAbort   = new CancellationTokenSource();
            Worker        = new Task(new Action(() => TcpWorker(addr)), WorkerAbort.Token);
            Worker.Start();
            BtnToggle.Text = "Stop";
        }