Exemple #1
0
        public void EntryPoint()
        {
            this.ThreadEndedEvent.Reset();

            try
            {
                // loop receiving from the server until:
                //   - the foreground thread wants to shutdown the connection. It has set
                //     the ShutdownFlag event.
                while ((ShutdownFlag.State == false))
                {
                    var message = InputQueue.WaitAndDequeue(this.ShutdownFlag.EventObject);
                    if (message != null)
                    {
                        if (message is CaptureContentMessage)
                        {
                            var captureMessage = message as CaptureContentMessage;
                            DoCapture(captureMessage.ScreenDefn, captureMessage.ScreenContent,
                                      captureMessage.CaptureFolderPath);
                        }
                        if (message is GeneralThreadMessage)
                        {
                            var generalMessage = message as GeneralThreadMessage;
                            var screenContent  = generalMessage.ScreenContent;
                        }
                    }
                }
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
        public void EntryPoint()
        {
            this.ThreadEndedEvent.Reset();
            try
            {
                // loop receiving from the server until:
                //   - the foreground thread wants to shutdown the connection. It has set
                //     the ShutdownFlag event.
                while ((ShutdownFlag.State == false))
                {
                    var message = InputQueue.WaitAndDequeue(this.ShutdownFlag.EventObject);
                    if (message != null)
                    {
                        // startup message sent by MainWindow after the threads have been
                        // started. Once startup is completed ( telnet negotiation ) the
                        // startup completed event is signaled back on the MainWindow.
                        if (message is TelnetStartupMessage)
                        {
                            var startupMessage = message as TelnetStartupMessage;
                            if (startupMessage.TypeTelnetDevice == TypeTelnetDevice.Terminal)
                            {
                                TelnetDisplayStartup(
                                    startupMessage.ServerConnectPack,
                                    startupMessage.NegotiateSettings,
                                    startupMessage.TelnetQueue,
                                    FromThread, ToThread,
                                    startupMessage.ClientWindow,
                                    startupMessage.TelnetStartupComplete);
                            }

                            else if (startupMessage.TypeTelnetDevice == TypeTelnetDevice.Printer)
                            {
                                TelnetPrinterStartup(
                                    startupMessage.ServerConnectPack,
                                    startupMessage.NegotiateSettings,
                                    startupMessage.TelnetQueue,
                                    FromThread, ToThread,
                                    startupMessage.ClientWindow,
                                    startupMessage.TelnetStartupComplete);
                            }
                        }

                        else if (message is GeneralThreadMessage)
                        {
                            var generalMessage = message as GeneralThreadMessage;
                            switch (generalMessage.MessageCode)
                            {
                            }
                        }
                    }
                }
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
        public virtual void EntryPoint()
        {
            try
            {
                using (this)
                {
                    using (ReadBuffer readBuf = new ReadBuffer())
                    {
                        // store the readBuf as a property so the ThreadSupervisor has access.
                        ReadBuffer = readBuf;

                        Supervisor.AssignCurrentReadBuffer(ReadBuffer);

                        Supervisor.AssureReceiveThread(Conn, mRunLog);

                        // run the actual command on the telnet server.
                        string[] respLines = null;
                        if (CommandMethod != null)
                        {
                            respLines = CommandMethod(this, ReadBuffer, WriteEventLog, CommandText);
                        }
                        else
                        {
                            respLines = this.CommandRoute.RunCommand(
                                this, ReadBuffer, WriteEventLog, CommandText);
                        }

                        this.RunLog.Write(respLines);

                        RunLog.Write(respLines);
                    }
                    RunLog.Write("Exit.");
                }
            }
            finally
            {
                // call the thread ended callback method.
                if (ThreadEndedCallback != null)
                {
                    ThreadEndedCallback();
                }

                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
        // The ReceiveThread is relatively simple.
        // It continuously reads from the socket connected to the telnet server. Whatever
        // is received is appended to a Read buffer and an event is signaled to alert
        // CommandThreads to come and get the data.  The CommandThread which gets the data
        // then empties the ReadBuffer and waits again on the "DataArrived" event to be
        // signaled by this thread.
        public void EntryPoint()
        {
            try
            {
                mRunLog.Write("Start reading from telnet server");

                while (mShutdownFlag.State == false)
                {
                    if (mConn.IsConnected == false)
                    {
                        break;
                    }

                    string s1 = mConn.Read();

                    // append what was just read to the ReadBuffer.
                    lock (mSupervisor.LockFlag)
                    {
                        if (mSupervisor.CurrentReadBuffer != null)
                        {
                            mSupervisor.CurrentReadBuffer.Buffer.Append(s1);
                        }

                        // Signal command threads that there is read data available. ( The command
                        // thread then resets the event after it checks/removes from the data buffer. )
                        mSupervisor.CurrentReadBuffer.GotDataEvent.Set();
                    }
                }

                mRunLog.Write("Exit.");
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
        public void EntryPoint()
        {
            this.ThreadEndedEvent.Reset();
            try
            {
                // loop receiving from the server until:
                //   - the foreground thread wants to shutdown the connection. It has set
                //     the ShutdownFlag event.
                while ((ShutdownFlag.State == false))
                {
                    var message = InputQueue.WaitAndDequeue(this.ShutdownFlag.EventObject);
                    if (message != null)
                    {
                        if (message is AidKeyResponseMessage)
                        {
                            var msg     = message as AidKeyResponseMessage;
                            var content = msg.ScreenContent.GetWorkingContentBlock();
                            BuildAndSendResponseDataStream(msg.AidKey, content, this.LogList);
                        }

                        else if (message is SaveScreenMessage)
                        {
                            var msg = message as SaveScreenMessage;
                            var ra  =
                                SaveScreenCommand.BuildSaveScreenResponse(msg.ScreenContent);
                            TelnetConnection.WriteToHost(
                                null, ra, this.Client.GetStream());
                        }

                        else if (message is ReadScreenMessage)
                        {
                            var msg = message as ReadScreenMessage;
                            var ra  =
                                ReadScreenCommand.BuildReadScreenResponse(msg.ScreenContent);
                            TelnetConnection.WriteToHost(LogList, ra, this.Client.GetStream());
                        }

                        else if (message is Query5250ResponseMessage)
                        {
                            var msg = message as Query5250ResponseMessage;
                            var ra  = Query5250Response.BuildQuery5250Response();
                            TelnetConnection.WriteToHost(LogList, ra, this.Client.GetStream());
                        }

                        // send the DataBytes contained in the message to the server.
                        else if (message is SendDataMessage)
                        {
                            var msg = message as SendDataMessage;
                            TelnetConnection.WriteToHost(
                                LogList, msg.DataBytes, this.Client.GetStream());
                        }

                        else if (message is GeneralThreadMessage)
                        {
                            var generalMessage = message as GeneralThreadMessage;
                            switch (generalMessage.MessageCode)
                            {
                            case ThreadMessageCode.ClearLog:
                            {
                                this.LogList.Clear();
                                break;
                            }
                            }
                        }
                    }
                }
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
Exemple #6
0
        public void EntryPoint()
        {
            this.ThreadEndedEvent.Reset();

            try
            {
                // loop receiving from the server until:
                //   - the foreground thread wants to shutdown the connection. It has set
                //     the ShutdownFlag event.
                while ((ShutdownFlag.State == false))
                {
                    var message = InputQueue.WaitAndDequeue(this.ShutdownFlag.EventObject);
                    if (message != null)
                    {
                        // list of defined screens. Message sent by the UI thread. Idea being
                        // that as a new screen is defined want to send message to this match
                        // thread so it will update itself with the current list.
                        if (message is AssignScreenDefnListMessage)
                        {
                            var assignMessage = message as AssignScreenDefnListMessage;
                            this.ScreenDefnList = assignMessage.ScreenDefnList;
                        }

                        else if (message is GeneralThreadMessage)
                        {
                            var generalMessage = message as GeneralThreadMessage;
                            var screenContent  = generalMessage.ScreenContent;
                            switch (generalMessage.MessageCode)
                            {
                            // message sent by MasterThread. MasterThread has completed the
                            // screen content. It sends message to PaintThread. And this msg
                            // to this MatchThread.
                            case ThreadMessageCode.MatchScreenContentToScreenDefn:
                            {
                                var matchDefn = FindMatchingScreenDefn(
                                    screenContent, this.ScreenDefnList);

                                // send match results to paint thread and tnClient window.
                                // ( send results whether a match found or not. )
                                var matchMessage =
                                    new MatchScreenDefnMessage(matchDefn, screenContent);
                                this.PaintThread.PostInputMessage(matchMessage);

                                // signal back to tnClient window.
                                this.TelnetWindowInputSignal(matchMessage);
                                break;
                            }
                            }
                        }

                        else if (message is CaptureAttributesMessage)
                        {
                            var captureMessage = message as CaptureAttributesMessage;
                            this.CaptureAuto       = captureMessage.CaptureAuto;
                            this.CaptureFolderPath = captureMessage.CaptureFolderPath;
                        }
                    }
                }
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
Exemple #7
0
        public void EntryPoint()
        {
            this.ThreadEndedEvent.Reset();

            try
            {
                // loop receiving from the server until:
                //   - the foreground thread wants to shutdown the connection. It has set
                //     the ShutdownFlag event.
                while ((ShutdownFlag.State == false))
                {
                    var message = InputQueue.WaitAndDequeue(this.ShutdownFlag.EventObject);
                    if (message != null)
                    {
                        if (message is PaintCanvasMessage)
                        {
                            var paintMessage  = message as PaintCanvasMessage;
                            var screenContent = paintMessage.ScreenContent;
                            var bi            = Window.Dispatcher.BeginInvoke(
                                DispatcherPriority.Input, new ThreadStart(
                                    () =>
                            {
                                if (screenContent is WindowScreenContent)
                                {
                                    var windowScreenContent = screenContent as WindowScreenContent;

                                    // find the existing ItemCanvas associated with the
                                    // WindowScreenContent.
                                    var itemCanvas = screenContent.FindItemCanvas(this.TelnetCanvas);
                                    //                      var itemCanvas = TelnetCanvas.FindChildCanvas(screenContent.ContentNum);
                                    if (itemCanvas == null)
                                    {
                                        itemCanvas = windowScreenContent.CreateItemCanvas(
                                            TelnetCanvas, MasterThread, this);
                                    }

                                    screenContent.PaintScreenContent(itemCanvas);
                                }
                                else
                                {
                                    screenContent.PaintScreenContent(this.TelnetCanvas);
                                }
                            }));
                        }

                        else if (message is ClearUnitMessage)
                        {
                            var cu = message as ClearUnitMessage;
                            this.TelnetCanvas.ContentNum = cu.ContentNum;
                        }

                        else if (message is KeyboardInputMessage)
                        {
                            var kbInput = message as KeyboardInputMessage;
                        }

                        else if (message is GeneralThreadMessage)
                        {
                            var generalMessage = message as GeneralThreadMessage;
                            var screenContent  = generalMessage.ScreenContent;
                            switch (generalMessage.MessageCode)
                            {
                            case ThreadMessageCode.ClearLog:
                            {
                                this.LogList.Clear();
                                break;
                            }

                            case ThreadMessageCode.ReportVisualItems:
                            {
                                IEnumerable <string> report = null;

                                var bi = Window.Dispatcher.BeginInvoke(
                                    DispatcherPriority.Input, new ThreadStart(
                                        () =>
                                    {
                                        report = screenContent.ReportVisualItems(this.TelnetCanvas);
                                    }));
                                bi.Wait();

                                this.LogList.AddReport(Direction.none, report);
                                break;
                            }
                            }
                        }

                        // message sent by TimerTick method of the HoverTimer class.
                        // Call draw hover box method on the UI thread.
                        // ( should be changed to push processing to a HoverThread. Hover
                        //   processing like ODBC calls to server should not be done on the
                        //   UI thread. )
                        else if (message is HoverMessageBase)
                        {
                            if (message is CanvasHoverMessage)
                            {
                                var hoverMessage = message as CanvasHoverMessage;
                                var bi           = Window.Dispatcher.BeginInvoke(
                                    DispatcherPriority.Input, new ThreadStart(
                                        () =>
                                {
                                    hoverMessage.ItemCanvas.DrawHoverBox(hoverMessage.HoverPos);
                                }));
                            }
                            else if (message is SuspendHoverMessage)
                            {
                                this.TelnetCanvas.HoverTimer.SuspendHover();
                            }
                            else if (message is ResumeHoverMessage)
                            {
                                this.TelnetCanvas.HoverTimer.ResumeHover();
                            }
                            else if (message is DelayHoverMessage)
                            {
                                this.TelnetCanvas.HoverTimer.DelayHover();
                            }
                        }

                        // message from match thread. Telling PaintThread of latest match.
                        else if (message is MatchScreenDefnMessage)
                        {
                            var screenDefn = message as MatchScreenDefnMessage;
                            var bi         = Window.Dispatcher.BeginInvoke(
                                DispatcherPriority.Input, new ThreadStart(
                                    () =>
                            {
                                this.TelnetCanvas.MatchScreenDefn = screenDefn.ScreenDefn;
                            }));
                        }
                    }
                }
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
        public void EntryPoint()
        {
            this.ThreadEndedEvent.Reset();

            try
            {
                // loop receiving from the server until:
                //   - the foreground thread wants to shutdown the connection. It has set
                //     the ShutdownFlag event.
                while ((ShutdownFlag.State == false) &&
                       (this.ConnectionFailedEvent.State == false))
                {
                    var message = InputQueue.WaitAndDequeue(
                        this.ShutdownFlag.EventObject, this.ConnectionFailedEvent.EventObject);
                    if (message != null)
                    {
                        if (message is DataStreamHeaderMessage)
                        {
                            var dshMessage = message as DataStreamHeaderMessage;
                            var dataBytes  = new byte[] {
                                0x00, 0x0A, 0x12, 0xA0, 0x01, 0x02,
                                0x04, 0x00, 0x00, 0x01, 0xFF, 0xEF
                            };
                            var dataMessage = new SendDataMessage(dataBytes);
                            this.ToThread.PostInputMessage(dataMessage);
                        }

                        else if (message is DataStreamHeader)
                        {
                            var dsh       = message as DataStreamHeader;
                            var dataBytes = new byte[] {
                                0x00, 0x0A, 0x12, 0xA0, 0x01, 0x02,
                                0x04, 0x00, 0x00, 0x01, 0xFF, 0xEF
                            };
                            var dataMessage = new SendDataMessage(dataBytes);
                            this.ToThread.PostInputMessage(dataMessage);
                        }

                        else if (message is PrinterDataBytesMessage)
                        {
                            var dataMessage     = message as PrinterDataBytesMessage;
                            var dataBytes       = dataMessage.DataBytes;
                            var dataBytesLength = dataBytes.Length;

                            // remove the IAC EOR from the end of the stream.
                            // ( the data stream may end with a partial control function which
                            //   is continued in the next data stream. Do not want to
                            //   confuse the FF EF EOR bytes as data bytes of the possible
                            //   incomplete control function. )
                            {
                                var endBytes = dataBytes.Tail(2);
                                var cmdCode  = endBytes.ParseTelnetCommandCode();
                                if ((cmdCode != null) && (cmdCode.Value == CommandCode.EOR))
                                {
                                    dataBytesLength -= 2;
//                  dataBytes = dataBytes.SubArray(0, dataBytesLength);
                                }
                            }

                            // there are remaining bytes from the previous dataBytes message.
                            // insert these remaining bytes after the dataStreamHeader.
                            if (this.RemainingBytes != null)
                            {
                                dataBytes = dataBytes.SubArray(0, dataBytesLength);
                                var headerLength = dataBytes.GetDataStreamHeaderLength();
                                if (headerLength != null)
                                {
                                    dataBytes =
                                        dataBytes.Insert(headerLength.Value, this.RemainingBytes);
                                    dataBytesLength += this.RemainingBytes.Length;
                                }
                            }

                            // parse the bytes.
                            var rv            = ServerDataStream.ParseByteArray(dataBytes, dataBytesLength);
                            var wrkstnCmdList = rv.Item1;
                            var responseList  = rv.Item2;
                            var dsh           = rv.Item3;
                            var telList       = rv.Item4;
                            var funcList      = rv.Item5;

                            // bytes at the end of the data stream that were not recognized as
                            // complete SCS function codes.  Save now and add to the front of the
                            // next data stream that arrives. ( add to front after the data
                            // stream header. )
                            this.RemainingBytes = rv.Item6;

                            if (1 == 1)
                            {
                                this.OpenDoc = PrintToPdf(dsh, funcList, this.OpenDoc);
                            }

                            var respBytes = new byte[] {
                                0x00, 0x0A, 0x12, 0xA0, 0x01, 0x02,
                                0x04, 0x00, 0x00, 0x01, 0xFF, 0xEF
                            };
                            var respMessage = new SendDataMessage(respBytes);
                            this.ToThread.PostInputMessage(respMessage);
                        }

                        else if (message is GeneralThreadMessage)
                        {
                            var generalMessage = message as GeneralThreadMessage;
                            switch (generalMessage.MessageCode)
                            {
                            case ThreadMessageCode.ClearLog:
                            {
                                break;
                            }
                            }
                        }

                        else if (message is ExchangeMessage)
                        {
                            var exchangeMessage = message as ExchangeMessage;
                            if (exchangeMessage.MessageCode == ThreadMessageCode.GetScreenContent)
                            {
                            }
                        }
                    }
                }
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
Exemple #9
0
        public void EntryPoint()
        {
            this.ThreadEndedEvent.Reset();
            var master = BaseMaster_InitialSetup();

            try
            {
                // loop receiving from the server until:
                //   - the foreground thread wants to shutdown the connection. It has set
                //     the ShutdownFlag event.
                while ((ShutdownFlag.State == false) &&
                       (this.ConnectionFailedEvent.State == false))
                {
                    var message = InputQueue.WaitAndDequeue(
                        this.ShutdownFlag.EventObject, this.ConnectionFailedEvent.EventObject);
                    if (message != null)
                    {
                        if (message is WorkstationCommandListMessage)
                        {
                            var cmdList = (message as WorkstationCommandListMessage).WorkstationCommandList;

                            var rv = this.BaseMaster.Apply(
                                cmdList, this.ToThread, this.PaintThread, this.LogList);
                            bool wtdApplied = rv.Item1;
                            this.BaseMaster = rv.Item2;

                            // signal the paint thread to paint the canvas with the screen
                            // content block.
                            if (wtdApplied == true)
                            {
                                this.BaseMaster.PostAidKey = this.PostAidKey;
                                this.PostAidKey            = null;
                                var masterCopy   = this.BaseMaster.Copy();
                                var content      = masterCopy.GetWorkingContentBlock();
                                var paintMessage = new PaintCanvasMessage(content);
                                this.PaintThread.PostInputMessage(paintMessage);
                            }

                            // send another copy of the screenContent to the match thread.
                            // Match thread will match the screen to the screen definitions.
                            // Looking for screen id, hover code, help text, etc.
                            if (wtdApplied == true)
                            {
                                var masterCopy = this.BaseMaster.Copy();
                                var content    = masterCopy.GetWorkingContentBlock();
                                this.MatchThread.PostInputMessage(
                                    ThreadMessageCode.MatchScreenContentToScreenDefn, content);
                            }
                        }

                        else if (message is KeyboardInputMessage)
                        {
                            var kbInput = message as KeyboardInputMessage;
                            if (kbInput.Text != null)
                            {
                                master = this.BaseMaster.GetWorkingContentBlock();
                                master.ApplyInput(kbInput);
                            }
                        }

                        // message sent from UI thread when the caret is moved. See the
                        // ItemCanvas class.
                        else if (message is CaretMoveMessage)
                        {
                            var caretMove = message as CaretMoveMessage;
                            master = this.BaseMaster.GetWorkingContentBlock();
                            master.ApplyCaretMove(caretMove);
                        }

                        // enter key has been pressed. UI thread sent the message to this
                        // Master thread. Master thread relays the message to the
                        // ToThread along with a copy of the master ScreenContent. ToThread
                        // creates and sends the response data stream based on the master
                        // screen content.
                        else if (message is AidKeyResponseMessage)
                        {
                            var msg = message as AidKeyResponseMessage;
                            this.PostAidKey   = msg.AidKey;
                            msg.ScreenContent = this.BaseMaster.Copy();
                            ToThread.PostInputMessage(msg);
                        }

                        else if (message is GeneralThreadMessage)
                        {
                            var generalMessage = message as GeneralThreadMessage;
                            switch (generalMessage.MessageCode)
                            {
                            case ThreadMessageCode.ClearLog:
                            {
                                this.LogList.Clear();
                                break;
                            }

                            // report visual items. Add screenContent to the message and
                            // send it to PaintThread.
                            case ThreadMessageCode.ReportVisualItems:
                            {
                                generalMessage.ScreenContent = this.BaseMaster.Copy();
                                PaintThread.PostInputMessage(generalMessage);
                                break;
                            }
                            }
                        }

                        else if (message is ExchangeMessage)
                        {
                            var exchangeMessage = message as ExchangeMessage;
                            if (exchangeMessage.MessageCode == ThreadMessageCode.GetScreenContent)
                            {
                                master = this.BaseMaster.GetWorkingContentBlock();
                                var masterCopy = master.Copy();
                                exchangeMessage.PostReplyMessage(masterCopy);
                            }
                        }
                    }
                }
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
        public void EntryPoint()
        {
            this.ThreadEndedEvent.Reset();

            try
            {
                byte[] buf = new byte[99999];
                this.ConnectionFailedException = null;
                var          gotRead   = new ManualResetEvent(false);
                IAsyncResult br        = null;
                int          bytesRead = 0;
                WaitHandle[] handles   = new WaitHandle[3];

                // loop receiving from the server until:
                //   - the foreground thread wants to shutdown the connection. It has set
                //     the ShutdownFlag event.
                //   - the connection to the server has failed.
                while ((ShutdownFlag.State == false) &&
                       (ConnectionFailedException == null))
                {
                    AsyncCallback callBack = null;
                    callBack = ar =>
                    {
                        try
                        {
                            bytesRead = this.Client.GetStream().EndRead(ar);
                            gotRead.Set(); // set the gotRead event. one of the events the
                                           // WaitAny is waiting on.
                        }
                        catch (ObjectDisposedException)
                        {
                            bytesRead = 0;
                        }
                        catch (InvalidOperationException)
                        {
                            bytesRead = 0;
                        }
                    };

                    // dequeue and process any message in the InputQueue.
                    if (this.InputQueue.Count > 0)
                    {
                        ReadAndProcessInputQueue();
                        continue;
                    }

                    try
                    {
                        // start a socket read. ( do not start a new read on every iteration
                        // of this loop. Something may have arrived on the InputQueue.
                        // Meaning the read of the prior iteration is active and is waiting
                        // to complete. )
                        if (br == null)
                        {
                            br = this.Client.GetStream().BeginRead(
                                buf, 0, buf.Length, callBack, null);
                        }

                        // wait for socket read to complete ( gotRead event is set. ) Or for
                        // something to arrive in the InputQueue.
                        handles[0] = this.ShutdownFlag.EventObject;
                        handles[1] = gotRead;
                        handles[2] = this.InputQueue.GotMessageEvent;
                        var ix = WaitHandle.WaitAny(handles);

                        if (ix == 1)
                        {
                            br = null;
                            gotRead.Reset();
                            if (bytesRead > 0)
                            {
                                byte[] recvBytes = LoadReceivedBytes(buf, bytesRead);

                                TrafficLogFile.Write(Direction.Read, recvBytes);

                                // print to printer data stream has started. route direct to
                                // printer thread.
                                if ((this.TypeDevice != null) &&
                                    (this.TypeDevice.Value == TypeTelnetDevice.Printer))
                                {
                                    var printerMessage = new PrinterDataBytesMessage(recvBytes);
                                    PostToProcessQueue(printerMessage);
                                }

                                else
                                {
                                    ProcessAndPostBytesReceived(recvBytes);
                                }
                            }
                        }
                    }
                    catch (Exception excp)
                    {
                        this.ConnectionFailedException = excp;
                        this.ConnectionFailedEvent.Set();
                    }
                }
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }