|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Have thread end if not finished in X secondsHow can I force a thread to end withing X seconds if it is not done?
I think this will have to be done by the thread itself. The main program starts threads to process incoming requests and the thread handles all processing then ends. Currently the main program doesn't monitor them at all. Hi,
We can use the WaitHandle.WaitOne overload that takes a timespan parameter indicating the number of milliseconds to wait for completion as a simplified thread / method execution timeout mechanism. Here is a nice post with detailed codes on this topic, How to set a maximum execution time on a thread, http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=1161 Hope this helps! Best regards, Colbert Zhou I must admit I don't understand all of the example but I think I get the
just of it. If I'm understanding correctly the main procedure will have to keep checking to see if the thread it launched has been executing to long and if so end it. Am I right? I'm not sure that's what I want but I'm still going over what I need. I do have a couple related questions. I'm wondering if the thread needs to do anything special when it's time to terminate. The sub that is the thread just ends--I was told there is nothing special I need to do. I'm wondering if the system is having a hard time cleaning up finished threads or something. Second question if when I shut down the main procedure I want it to immediately stop all threads it has launched is there a way I can make do this without having to keep track of each one individually? Like pulling a list of all running threads by the name of the program and ending each. Colbert Zhou [MSFT] wrote: Show quoteHide quote > Hi, > > We can use the WaitHandle.WaitOne overload that takes a timespan parameter > indicating the number of milliseconds to wait for completion as a > simplified thread / method execution timeout mechanism. Here is a nice post > with detailed codes on this topic, > > How to set a maximum execution time on a thread, > http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=1161 > > Hope this helps! > > Best regards, > Colbert Zhou >
inputbox
How do I create new app with data access? Concurrency error on update VB.NET Charting Solution HTML, CSS and JavaScript in a Gridview How To :App.Config Duplicated data - how to understand it please? is this possible? Pass a structure to a C++ dll Launch .NET application through notification or windows messaging Option |
|||||||||||||||||||||||