|
-
Apr 9th, 2015, 02:21 PM
#35
Re: Understanding Multi-Threading in VB.Net
I assume you're processing data in the DataReceived event, which executes in a thread kicked off by the SerialPort object.
If your data is coming fast enough that your GUI has a hard time doing the things it needs because of constant invoking, as Niya says you can try BeginInvoke instead which is asynchronous.
I'm a little cautious with BeginInvoke. If the data is slow enough that I know I won't be overlapping BeginInvoke calls, then using BeginInvoke to avoid holding the receiving thread any longer than necessary I like. But if the data is coming fast, and I'm calling BeginInvoke repeatedly, so that calls can overlap with previous asynchronous invocations not completed, can lead to issues, depending on if you're using reference types, etc.
My preference is to push the received data in the serial receiver onto a concurrent queue, and have a "GUI Timer", that is responsible in the GUI thread of periodically checking the queue and processing the data and updating the GUI elements. Usually I have the GUI timer operating at 10hz to update the GUI, while the various Serial ports, and Ethernet ports communicating with various machines at various rates at the same time.
That keeps the GUI thread responsive, and reflecting data the user needs, and keeps from tying up the various communication interfaces that are receiving data.
Last edited by passel; Apr 9th, 2015 at 02:24 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|