private void CallStateChange(BotConnectionState state) { lock (mSync) { mState = state; } if (StateChanged != null) { StateChanged(this, state); } }
private void MConnection_StateChanged(IBotConnection sender, BotConnectionState state) { if (!mRunning) { return; } if ((state == BotConnectionState.Stopped) || (state == BotConnectionState.Failed)) { ProtocolError((mConnection.LastError != null) ? mConnection.LastError : "Connection failed."); } else if (state == BotConnectionState.Started) { mConnection.SendMessage(Encoding.ASCII.GetBytes("INIT")); mState = ProtocolState.InitSent; UpdateTimeout(); } }
public void Start() { lock (mSync) { if ((mState != BotConnectionState.Stopped) && (mState != BotConnectionState.Failed)) { throw new InvalidOperationException(); } mLastError = null; mLastErrorDetails = null; mWriteQueue.Clear(); mState = BotConnectionState.Starting; mStopping = false; mReadThread = new Thread(ReadWorker); mReadThread.Start(); mWriteThread = new Thread(WriteWorker); mWriteThread.Start(); } if (StateChanged != null) { StateChanged(this, mState); } }
private void ThreadFinished(bool read, bool write, string error, string details) { lock (mSync) { if (error != null) { mLastError = error; mLastErrorDetails = details; } if (read) { mReadThread = null; } if (write) { mWriteThread = null; } if ((mReadThread == null) && (mWriteThread == null)) { BotConnectionState state = (mLastError != null) ? BotConnectionState.Failed : BotConnectionState.Stopped; mDispatcher.BeginInvoke(new CallStateChangeEventHandler(CallStateChange), state); } else { mStopping = true; if (mReadThread != null) { mReadEvent.Set(); } if (mWriteThread != null) { mWriteEvent.Set(); } } } }