Hi everyone,
I'm new to VB.NET 2005 and have stumbled across a very strange problem for which I cannot find a solution for. I am literally pulling my hair out!
I'm developing an application for the Pocket PC 2003. I have a form which uses a Port to read incoming data. The data is read at 1 second intervals using a Timer control. The data that is read is then updated in to fields and labels on the form.
It all works great until I display a message box or display another form. The form (the that needs to be updated) simply stops updating. I have put a debug into the Timer's "Timer_Tick" event and nothing happens. So either the Timer is stopping or the port stops receiving data....or both. I am forced to restart the port and the timer from a button I put on the form for the updating to begin again! But ofcourse this is not what I want. I need the form to update at all times.
Can anyone please help
Thank you,
Chris

Strange problem on Pocket PC using VB.NET 2005
Speedipus
I'd say that's expected. MessageBox (and probably modal dialog) would block UI thread which is used to update UI as well as to fire timer events (assuming you're using System.Windows.Forms.Timer).
If you're using System.Threading.Timer, it won't be blocked since it fires on separate thread. However, you can not update UI from another thread and would have to use Control.Invoke(). Which would wait till UI thread unblocked before it updates anything, so it makes no difference.
The only solution here is not to block UI thread. Also it's a good idea to use serial port DataReceived event instead of timer. You would have to use Control.Invoke() to marshal data back to the UI thread.
rico75
That means your code in all UI events should be done with what it's doing as fast as possible and return promptly so UI which is serviced by this thread won't freeze. All the UI stuff is done by the CPU cycling in the loop. Once this loop is stopped, UI would no longer respond. It’s like a secretary talking on a phone – nothing’s get done at that time. So, waiting for something (e.g. for data to arrive from serial port, user to press button in message box and so on) is not acceptable.
Actually, as far as I remember, VB6 uses pretty much the same model. Add an infinite loop to some event and UI will die.
Haggerty
Thanks for your reply Ilya. Yes I am using the System.Windows.Forms.Timer. I have code in the "Timer_Tick" event that is supposed to update the fields and labels with the data that is read from the COM port. I have also tried doing this using the Datareceived event of the port but then nothing was getting updated at all so then I switched to the Timer method.
VB.NET 2005 is so different to VB6 I'm having trouble getting my head around it!
How do I "not block" the UI thread
Thanks