Click here to Skip to main content
15,887,936 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I'm new in the design workflow.
I have a question:
I have a graphics interface unit, a desired workflow state machine and a thread that polls a hardware device and receives a response every 1 ms (approximately) via RS232.
These responses may alter the state machine.
The GID may modify the state machine.
I found lots of examples for host-workflow communication, but I do not know how to handle this thread.
Could you help me and give me some suggestions?
Bye
Posted

Use a Queue<T>[^] to enqueue the received data and have another thread dequeue the data for processing.

If you are use .NET 4, then use the new ConcurrentQueue<T>[^] class. Check this link BlockingCollection and IProducerConsumerCollection[^]

Workflow can be:
1. Receive data on RS232 / Serial port.
2. Pre process data received.
3. Enqueue data in an Queue class.
4. Repeat, goto step 1

In another thread you then:
1. Dequeue an Queue class.
2. Post process data.
3. Do the your thing.
4. Repeat, goto step 1.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 6-Jun-11 13:25pm    
This is good, but Queue is not enough, it should be a blocking queue, which is not easy to make for everyone. Concurrent queue needs explanation. My 5, but I have my own publication which explains everything.

Please see my solution.
--SA
Kim Togo 6-Jun-11 14:25pm    
Thanks SA
In addition to the solution by Kim:

Queue is not enough. Communication requires a blocking queue.
If you're not using .NET 4, or you are but want to know how to use it, please use my Tips/Trick article with full source code and detailed usage samples:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

—SA
 
Share this answer
 
Comments
Kim Togo 6-Jun-11 14:25pm    
My 5 for the good Tips/Tricks
Sergey Alexandrovich Kryukov 6-Jun-11 14:30pm    
Thank you, Kim.
--SA
thatraja 6-Jun-11 23:41pm    
It's a good Tip/Trick SA, Already in my bookmarks
Sergey Alexandrovich Kryukov 6-Jun-11 23:45pm    
Thank you, Raja.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900