I recently played with the new Async CTP, and I came across a situation where I am not sure how to proceed.
In my current code base, I use the concepts of "jobs" and "job manager". Tasks exist solely to process the original message, send a response, and wait for a response.
I already have existing code based on synchronous sockets, where the network stream waits for data to arrive, and then passes it along with the event handler and, ultimately, to the task manager.
The task manager looks for what work will process the message, and passes it.
So the scenario is this:
- The task manager receives a new message and starts the task.
- The job begins, processes the message, and sends a response message.
- At this point, the task will wait for a response to the answer.
Here is an example of pseudo code:
class MyJob : Job { public override void RunJob( IPacketMsg packet ) {
But I'm not quite sure how to proceed in step 3. The task manager will receive an answer, and then transfer it to the current work. But I'm not sure how to make the work wait for an answer.
I considered creating an expected task that simply blocks WaitHandle, but is this a better solution?
Are there any other things that I could do in this case?
Edit With regard to Async CTP, what happens when the user interface is not in use. I read Eric Lippert on the Async blog, but I don't think it ever touched on how everything works in the background without a user interface thread (does it distract the background worker or ...?)