The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

DataReceived Event and polling.

I am doing some serial communication to a divice using .NET 2.0.  The device has a set of simple commands, each command and responce is a fix size. Each command will generate a responce and a new command can not be sent until the responce from the previous command has been recived.  I have set the DataReceived event handler ta a
method that will read the responce data. That part works OK.  There is a flag in the event handler that I set when I read the response. I poll for that flag to see when I can sent the next command. My question is is there any way I can know when it is OK to send the next command without polling?
dlb Send private email
Sunday, July 09, 2006
 
 
Read the specs for the device and it'll tell you the proper protocol.
Bill
Sunday, July 09, 2006
 
 
My question has to do more with the software design. The DataReceived event is raised on a secondary thread. If there was some way to get the thread Id of the event handler I could do a thread Join to tell when the data reading is done.
dlb Send private email
Sunday, July 09, 2006
 
 
MSDN tells me that DataReceived events occurs on a worker thread.  System.Threading.Monitor with its Wait and Pulse methods might do what you want. 

It sounds like your app is event driven, if so you can  create a CanSend event and have your DataReceived handler raise this when it is safe to send another command.
Brian Send private email
Sunday, July 09, 2006
 
 
> If there was some way to get the thread Id of the event handler I could do a thread Join to tell when the data reading is done.

If you want to wait (block) on something you could wait on a mutex that's set by the secondary thread.
Christopher Wells Send private email
Monday, July 10, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz