Note that there are some explanatory texts on larger screens.

plurals
  1. POSerial port worker thread freezing randomly
    primarykey
    data
    text
    <p>I am calling my background worker by the following code:</p> <pre><code>private void UpdateDataTimer_Tick(object sender, EventArgs e) { if (!serialPortWorker.IsBusy) { serialPortWorker.RunWorkerAsync(); } } </code></pre> <p>My <code>DoWork</code> event is as follows:</p> <pre><code>private void serialPortWorker_DoWork(object sender, DoWorkEventArgs e) { //Configures serial port connection.BaudRate = 19200; connection.DataReceived += new SerialDataReceivedEventHandler(DataReceivedEvent); //Sends the commands for opening diagnostics string[] init_commands = { "STRING", "STRING", "STRING", "STRING", "STRING" }; foreach (string command in init_commands) { connection.WriteLine(command + connection.NewLine); Thread.Sleep(1000); } const string constant_message_section = "G03"; string[] command_list = { "62", "64", "5C" }; //Writes all commands to all radio addresses foreach (int address in radioAddresses) { foreach (string command in command_list) { for (int i = 0; i &lt; MAX_ATTEMPTS; i++) { connection.WriteLine(constant_message_section + address.ToString("X4") + command); Thread.Sleep(500); } } } Thread.Sleep(1000); //Give a little time for all responses to come in } </code></pre> <p>For some reason, after a few hundred calls of the <code>UpdateDataTimer_Tick</code> event, it will not run the <code>serialPortWorker</code> any more. I put a debugger at <code>if (!serialPortWorker.IsBusy)</code>, and it indicated that the <code>serialPortWorker</code> is still busy. It must be hanging up somewhere in the <code>DoWork</code> event, right? Any ideas why?</p> <p>For those that are interested, the data received event is as follows:</p> <pre><code>public void DataReceivedEvent(object sender, SerialDataReceivedEventArgs e) { SerialPort sp = (SerialPort)sender; string receive = sp.ReadLine(); try { Debug.Logger.WriteToDebug("Data Received Serial Port: " + receive); } catch { } try { int unit_address = Int32.Parse(receive.Substring(1, 4), System.Globalization.NumberStyles.HexNumber); if (radioAddresses.Contains(unit_address)) { int radio_index = radioAddresses.IndexOf(unit_address) + 1; int max_index = radio_index * 3; integrityMonitor[radio_index] = DateTime.Now; //Last updated time int message_data = 0; if (receive.Contains("66")) { //Stuff } else if (receive.Contains("61")) { //Stuff } else if (receive.Contains("55")) { //Stuff } } } catch { } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload