how kill a thread that is on wait state??????
-
hi i am working on a project that neede to use multi threading in a method i use Monitor.Enter(Object) for define a critical area. now if few thread wants to execute the method , monitor.Enter avoid to run Synchronize the method by all thread at the same time, so few threads will be on wait state. now my problem is may be user wants to cancell the execution of a thread that is on wait state how can i kill the thread.??? if i call Thread.CurrentThread..Interrupt() below error appears: "cannot kill a thread that was in wait state" :-\ this is not complete error, this is just shortest of error. thank you
nobody help you... you have to help you yourself and this is success way.
-
hi i am working on a project that neede to use multi threading in a method i use Monitor.Enter(Object) for define a critical area. now if few thread wants to execute the method , monitor.Enter avoid to run Synchronize the method by all thread at the same time, so few threads will be on wait state. now my problem is may be user wants to cancell the execution of a thread that is on wait state how can i kill the thread.??? if i call Thread.CurrentThread..Interrupt() below error appears: "cannot kill a thread that was in wait state" :-\ this is not complete error, this is just shortest of error. thank you
nobody help you... you have to help you yourself and this is success way.
The thread that currently owns the lock should use some mechanism to indicate a "cancelled" state and then release the lock. After acquiring a lock, waiting threads should first look at the cancelled state before proceeding. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
hi i am working on a project that neede to use multi threading in a method i use Monitor.Enter(Object) for define a critical area. now if few thread wants to execute the method , monitor.Enter avoid to run Synchronize the method by all thread at the same time, so few threads will be on wait state. now my problem is may be user wants to cancell the execution of a thread that is on wait state how can i kill the thread.??? if i call Thread.CurrentThread..Interrupt() below error appears: "cannot kill a thread that was in wait state" :-\ this is not complete error, this is just shortest of error. thank you
nobody help you... you have to help you yourself and this is success way.
You might try to use
Monitor.TryEnter
. This does not block, however you have to do this in a loop until you finally get the lock. This is called polling/busy waiting and can cost some CPU cycles, but maybe it works better in your case.while(!Monitor.TryEnter(obj) || !shouldStop)
{
Thread.Sleep(1000);
}regards
-
hi i am working on a project that neede to use multi threading in a method i use Monitor.Enter(Object) for define a critical area. now if few thread wants to execute the method , monitor.Enter avoid to run Synchronize the method by all thread at the same time, so few threads will be on wait state. now my problem is may be user wants to cancell the execution of a thread that is on wait state how can i kill the thread.??? if i call Thread.CurrentThread..Interrupt() below error appears: "cannot kill a thread that was in wait state" :-\ this is not complete error, this is just shortest of error. thank you
nobody help you... you have to help you yourself and this is success way.
I am not sure about the article but even MSDN says that you cannot take full control of a thread. the mostr you can do is to make it wait. I am not sure about article but I remember these things. Hope it helps.
"If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry
-
The thread that currently owns the lock should use some mechanism to indicate a "cancelled" state and then release the lock. After acquiring a lock, waiting threads should first look at the cancelled state before proceeding. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
thanks alot mark but whats that mechanism? i tray alot but cannot find a solution. please tell me completely
nobody help you... you have to help you yourself and this is success way.
Add a boolean property to the class perhaps? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: