dotnet clr:
Hi!
In a previous post I discussed the most suitable approach for
multi-threading in
a provided scenario and was provided very usefull feedback (thanks Stefan
Simek, Jon Skeet and John Conwell).
I am using a WaitHandler.WaitAll to wait for all of my threads to finish
executing,
but I would also like to leverage the timeout feature of this method so that
I wont
end up in a terribly long wait.
On of the last questions I asked was how to shutdown my worker threads if
the
timeout kicked in and Jon pointed me to
http://www.yoda.arachsys.com/csharp/threads/shutdown.shtml
At first I thought this would be the way to go, but when I saw that Jons
code was
based on multiple items being processed from a worker thread, because of the
while-loop in his skeleton code.
In my case I will only have one data collection taking place, for example a
call to
a database or a webservice. Now calling a webservice is a synchronous call,
i.e
blocking call (if I don't use the async begin/endxxx methods), thus the
worker thread
will be blocking executing inside that thread until the webservice responds.
Now
what happens if I call the webservice from the workerthread.. it takes ages
to
respond and in the meantime the timeout kicks in from the mainthreads and
abandons
the wait.. now how do I gracefully shutdown the worker threads in that case?
Should I use the async calls to the webservice and leverage a pattern like
the one Jon
illustrates in his article or is there perhaps another way? The same could
be said for
database access.. it could take time, even timeout and I would be left with
a worker
thread hanging around...The database calls can't be done async (since this
isn't a 2.0
application ;) ..
<insert suggestions / feedback here>
=)
Thanks!