Callback Delimma...

A

altagrego

Greetings,

1. Multiple threads will make REQUESTs. (I synchronous request per
thread) The number of threads could vary.. (1..n) where n could be
10,000.

2. A separate thread will be monitoring the central RESPONSE
depository. (queue/list whatever...)

3. Each request/response will have a matching unique ID so that the
monitoring thread can route the response back to the proper thread
that made the request. So the monitoring thread will simply receive
the response, determine it's destination (request thread), and send it
back...

4. I don't want 10,000 threads to poll or search for their specific
response ! That would be very inefficient...

5. My setup is : (xp, vs2005, framework 2.0, c#)

How is the "best" way to implement STEP 3 in a C# ????
 
C

Chris Mullins [MVP]

You've pretty much described IAsyncResult , and the problem that it was
designed to solve.

I would suggest reading some articles people have put together on writing
asynchronous code, and making use of IAsyncResult. This pattern makes use of
a ManualResetEvent, so each of your 10k threads ends up blocking on a
particular event, and the wait is therefore pretty efficient. When the
"worker" thead completes a task, it sets the event inside the AsyncResult,
which causes the originally blocked thread to wake up and being processing.

I would normally send you some links, but there are so many articles on the
web, that you can just hit Google and get more than you'll know what to do
with...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top