public void AsyncSend(List <String> msgs, UInt32 Nreps, Boolean bWait) { if (!m_bConnected) { AsyncSendCompleted?.Invoke(this); return; } if (m_sendThread != null) { if ((m_sendThread.ThreadState == ThreadState.Unstarted) || (m_sendThread.ThreadState == ThreadState.Stopped)) { m_sendThread = null; } } m_bAbortAsyncSend = false; m_sendThread = new Thread(new ThreadStart(() => AsyncSendThread(msgs, Nreps, bWait))) { Name = "Connector_AsyncSendThread" }; m_sendThread.Start(); return; }
private void AsyncSendThread(List <String> msgs, UInt32 Nreps, Boolean bWait) { for (uint k = 0; k < Nreps; ++k) { foreach (String cmd in msgs) { if (cmd.Trim() == "") { continue; } if (m_bAbortAsyncSend) { break; } Send(cmd.Trim()); if (bWait) { uint w = 0; while (!IsCmdCompleted && !m_bAbortAsyncSend) { System.Threading.Thread.Sleep(100); if (++w == 10) { ClearRxDebit(); NewRespData?.Invoke(this, "[[giving up on answer]]"); break; } } } } if (m_bAbortAsyncSend) { break; } } AsyncSendCompleted?.Invoke(this); return; }