/// <summary> /// Connect the protocol. /// </summary> /// <param name="opCompleteEvent"></param> public void Connect(OperationCompleteEvent opCompleteEvent) { if (!this.isConnected && this.settings.Enabled) { this.isConnecting = true; this.protocolServer.OnBeginConnect(); opCompleteEvent.RegisterEvent(new OperationCompleteHandler(OnConnectionComplete)); // abort the connection thread if exists if (this.connectionThread != null) { try { if (this.connectionThread.IsAlive) { this.connectionThread.Abort(); } } catch {} this.connectionThread = null; } // start the connection on a new thread. this.connectionThread = new ArgThread(new ConnectHandler(pConnect)); this.connectionThread.Start(new object[] { opCompleteEvent }); } }
/// <summary> /// Occurs when disconnection is complete. /// </summary> /// <param name="args"></param> /// <param name="tag"></param> private void OnDisconnectionComplete(OperationCompleteArgs args, object tag) { if (args.Success) { this.protocolServer.OnNormalDisconnect(); this.isConnected = false; } this.connectionThread = null; }
/// <summary> /// Occurs when the protocol has completed canceling the connection /// </summary> /// <param name="args"></param> /// <param name="tag"></param> private void OnCancelationComplete(OperationCompleteArgs args, object tag) { this.protocolServer.OnConnectCanceled(); try { if (this.connectionThread.IsAlive) { this.connectionThread.Abort(); } } catch {} this.connectionThread = null; }