Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Events & Display handling by OS
I am developing a software which communicates over the CAN network. It
has a thread to transmit and another to receive the messages. After
sending some messages the transmit thread holds till it receives a
response from the network. Also the messages trans/received have to be
displayed on the GUI in real time.
For holding the transmit thread, I am using AutoResetEvent.Wait()
When the response is received I am using AutoResetEvent.Set()
For Displaying the messages in real time i am using Virtual ListView
for updating the GUI.
Now the transmit thread sometimes does not recognise that a message is
received, even when the AutoResetEvent is Set.
I think the problem is due to processing of Display and the processing
of AutoResetEvent. I think both the messages for display and autorest
are put in the message queue of the OS, which will process them
sequentially. If the display takes more time to update then the
processing of autoresetevent will take more time.
Is there any solution to this problem?
I think i need to look ahead at two fronts
1. Either change the way i update the GUI with the messages, so that i
may have to change to something other than Virtual ListView
2. Or Find some other way to unblock the transmit thread when i
receive the message.
To provide a code sample which will generate the problem in question
is not possible.
Reason: There are two different things happening for the application,
which the OS is handling.
1: The OS is handling updation of Virtual ListView
2: The Os is handling informing the waiting thread about the event.
The above two things are distributed across various functions, code
listing which will constitute the complete project code. For testing
purpose, I had tried with simple value types like Strings, but that
didnt produce the error. Only when i am using the CAN objects for
display update, i face the problem.
So, at present i believe we first need to theoretically solve the
problem, and then maybe get onto the code.
For added information about the code:
1. The receive thread raises the autoresetevent and also makes a
boolean variable true. This way when the transmit thread is waiting,
it can either get the boolean variable to be true or the event.
2. The boolean variable is declared as static volatile
So the question is
1. While the OS is busy updating the virtual listview, it cannot
process any other event. Is there any method force the OS to use the
thread pool for the display update, and continue catering to the
2. Is there any other way other than a) raising an event & b) boolean
variable to communicate between the threads about the state of the
3. Or should there be some other control be used for displaying the
messages, i.e instead of using Virtual Listview, some other things
cvan be used?