MultiThreading in C# and how to handle
I have a requirement in which i need to call开发者_StackOverflow中文版 webservice 12 times for one request. What i am planning creating that number of threads and call the service from ThreadStartMethod ... Now the questions are
- I need to kill all other threads if i got proper result from any of the response
- I heard killing thread by using Thread.abort is dangerous .
Please advice
Thanks
Don't use threads at all. See my answer to this question here:
Using ThreadPool threads with long running ADO.NET queries. Is this scalable?
Use asp.net's built-in async processing instead.
Thread.abort will throw an ThreadAbortException and is usually not a very good idea, since aborting a thread will always leave your application in an undefined state.
It's considered to be better practice to do some sort of polling to stop the thread in a more 'graceful' way when a flag is set.
精彩评论