public Target(resend inResend) { myResend = inResend; m_Commands = new ConcurrentQueue <ICommand>(); m_queueEvent = new ManualResetEvent(false); m_finishedEvent = new ManualResetEvent(false); m_thread = new Thread(new ThreadStart(Run)); m_thread.IsBackground = true; m_thread.Start(); }
/// <summary> /// This method is called by the Target in a separate thread /// </summary> public virtual void Execute(resend myRerun) { m_TransmitTelegram = new ProtocolFrame(m_DestinationAddress, m_Command, m_Data); { m_Latch.Reset(); IsTimeout = false; m_Interface.RegisterListener(this); m_CommandResult = WcaInterfaceCommandResult.InProgress; m_Interface.Send(m_TransmitTelegram.Telegram); try { if (!m_Latch.WaitOne(Timeout)) { //timeout IsTimeout = true; m_CommandResult = WcaInterfaceCommandResult.ExecutionTimeout; if (myRerun != null) { myRerun(m_Interface.GetName(), m_Command, m_Data, m_Name); } } else if (Validate(m_ReceivedTelegrams)) { m_CommandResult = WcaInterfaceCommandResult.PosAck; } else { m_CommandResult = WcaInterfaceCommandResult.NegAck; if (myRerun != null) { myRerun(m_Interface.GetName(), m_Command, m_Data, m_Name); } } m_Latch.Reset(); } catch (System.Exception ex) { Debug.WriteLine(ex); } m_Interface.UnregisterListener(this); NotifyListener(this); } }