// Dispose(bool disposing) executes in two distinct scenarios. // If disposing equals true, the method has been called directly // or indirectly by a user's code. Managed and unmanaged resources // can be disposed. // If disposing equals false, the method has been called by the // runtime from inside the finalizer and you should not reference // other objects. Only unmanaged resources can be disposed. protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this._disposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { if (_vt100 != null) _vt100 = null; } if (ended != null) ended.Dispose(); // Note disposing has been done. _disposed = true; } }
private const bool enterEncodeCRLF = true; // Only one encoding used for port serial session. /// <summary> /// Switches to VT100 mode. /// enterEncodeCRLF: VT100 encoding for Enter key. True: CR+LF for Enter. False: CR for Enter. /// </summary> private void SetupVt100(bool enterEncodeCRLF) { _vt100 = new AnsiEscape<startPortSerialSession>(this); // start the read on another threa. Thread receiver = new Thread(new ThreadStart(Receive)); receiver.Start(); // This method blocks. The only way to exit is kill the process // or press Ctrl + C _vt100.ReadConsole(enterEncodeCRLF); // wait at most for 3 seconds for the read thread to end. ended.WaitOne(3000); // undo all VT100 console changes. fall through will reach this method. _vt100.RevertConsole(); // dispose of the Vt100 class. _vt100 = null; // write the tare down message Console.WriteLine(); Console.WriteLine(terminationMessage); Console.WriteLine(); }