Reputation: 61503
Suppose I have to spawn off 100 threads to access a HTTP resource. Since all these threads will be doing the same thing (except for the target url), what is the best way to spawn these threads in pending mode, and then launch them as needed?
For comparison purposes, this code seems to have a signficant delay when starting up, and I'd like to avoid that if possible.
myClient client = new myClient(Machine,Start, Stop, Interval);
var threadDelegate = new ThreadStart(client.TestLoop);
var newThread = new Thread(threadDelegate);
if (DoStart)
newThread.Start();
Also I'd like to know the right way to kill the thread, so that I can manually call some destructors in almost all cases.
Upvotes: 0
Views: 59
Reputation: 29083
take a look at the section "Exposing Complex EAP Operations As Tasks" on http://msdn.microsoft.com/en-us/library/dd997423.aspx
the example given there uses WebClient to asynchronously make HTTP requests
Upvotes: 0
Reputation: 458
I have used the following class in the past to do work similar to this - it may help you out:
Upvotes: 1