Here is my problem. I have a thread which constantly polls a piece of hardware's serial output. Every time it detects a certain serial sequence, it triggers an event handler wherein I have code which processes said sequence.
The problem is that the processing is quite time intensive. I noticed that when the program is in the event handler, the hardware is not being polled. If possible, I would like the processing and polling to happen concurrently (in separate threads). This is because due to the time spent solely in the event handler, I am missing some hardware events as I have to poll the piece of hardware as often as possible. By spending time exclusively in the processor method, I am effectively reducing the duty cycle of my hardware. I can afford some concurrence since the hardware has some amount of latency. I issue a command and some time will pass until it is ready and it triggers the event which initiates the processing.
I've tried creating a thread to process the serial data, but its not working. What happens is that when the code exits the MyEventHandler method, it seems to dispose of the passed data hence making the new thread useless.
Can anybody help me or at the very least point me in the right direction? Thanks!
The problem is that the processing is quite time intensive. I noticed that when the program is in the event handler, the hardware is not being polled. If possible, I would like the processing and polling to happen concurrently (in separate threads). This is because due to the time spent solely in the event handler, I am missing some hardware events as I have to poll the piece of hardware as often as possible. By spending time exclusively in the processor method, I am effectively reducing the duty cycle of my hardware. I can afford some concurrence since the hardware has some amount of latency. I issue a command and some time will pass until it is ready and it triggers the event which initiates the processing.
I've tried creating a thread to process the serial data, but its not working. What happens is that when the code exits the MyEventHandler method, it seems to dispose of the passed data hence making the new thread useless.
Code:
void MyEventHandler (object s, customeventargs e) { Processor p = new Processor(e); Thread t = new Thread ( new Threadstart(p.process)); t.start(); } class Processor { customeventargs sd; public Processor(customeventargs args) { sd = args; } public Process { //Perform operation on sd } }
Comment