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!
Jon Skeet [C# MVP] - 21 Jun 2005 20:48 GMT
<snip>
> <insert suggestions / feedback here>
Just to say I *will* be answering this post, as soon as I get time to
do it justice. Don't think I've abandoned you :)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Netveloper - 22 Jun 2005 09:42 GMT
> <snip>
>
>> <insert suggestions / feedback here>
>
> Just to say I *will* be answering this post, as soon as I get time to
> do it justice. Don't think I've abandoned you :)
*phew* Nice of you to let me know =) Looking forward to some
insight into this =P Amazing how much programming you can do
over the years and manage to stay away from the "dark side" of
multihreading ;)
Jon Skeet [C# MVP] - 26 Jun 2005 15:22 GMT
<snip>
> 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
[quoted text clipped - 5 lines]
> the mainthreads and abandons the wait.. now how do I gracefully
> shutdown the worker threads in that case?
Well, why do you *need* to? If they're not doing anything, I'd just let
them hang around. If the app should stop at that point, make them
background threads. If the app needs to keep going, you could set a
variable to say that you're no longer interested in the results of the
webservice call, and make the webservice thread test that after the
call, and act accordingly.
For database access, you may be able to cancel the request depending on
what database you're using etc. (See things like SqlCommand.Cancel.)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too