private void stopServer()
 {
     try
     {
         this.cancelTokenSource.Cancel();
     }
     catch (OperationCanceledException) { }
     this.currentServer.Stop();
     this.currentServer.Dispose();
     this.cancelTokenSource.Dispose();
     this.currentServer = null;
 }
        private void startServer()
        {
            this.writeSettingsToConfig();

            Action<string> logger = (message) =>
            {
                MethodInvoker action = () => { this.txtLog.AppendText(String.Format("{0}{1}: {2}", Environment.NewLine, DateTime.Now, message)); };
                if (this.InvokeRequired)
                {
                    this.Invoke(action);
                }
                else
                {
                    action.Invoke();
                }
            };
            this.cancelTokenSource = new CancellationTokenSource();
            this.currentServer = new Server(logger, this.cancelTokenSource.Token, this.config);
            this.currentServer.Start();
        }