How to revoke the sleeping threads???
Ex. System.Threading.Thread.Sleep(15000); //it sleep for some time... before the time ends,i need to wakeup the thread..
How ????
Thanks in Advance
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
How to revoke the sleeping threads???
Ex. System.Threading.Thread.Sleep(15000); //it sleep for some time... before the time ends,i need to wakeup the thread..
How ????
Thanks in Advance
You can't. However, if you control the code in the sleeping thread, you can accomplish this with a modification to how you "sleep". Instead of calling Sleep, call Wait on an EventWaitHandle passing a timeout. If the event isn't signaled, the effect is the same as sleeping. If the event is signaled, you'll "wake up" sooner, as you're wanting to do.
Calling sleep is almost the same as a //TODO in your code. It is very rare that it is the appropriate way to solve the problem. What you are normally doing is saying, "wait until x happens, which will probably happen in under t time". You should always try to find a way to verify that x has happened and then send a notification to the waiting thread.
I sometimes use sleep to prove that my issue is a synchronization issue and then come back and write the logic. Of course, there are cases where it is necessary.
obrienslalom said:Calling sleep is almost the same as a //TODO in your code. It is very rare that it is the appropriate way to solve the problem. What you are normally doing is saying, "wait until x happens, which will probably happen in under t time". You should always try to find a way to verify that x has happened and then send a notification to the waiting thread.
I sometimes use sleep to prove that my issue is a synchronization issue and then come back and write the logic. Of course, there are cases where it is necessary.
not sure i would go THAT far...
example code for an app that gets text from a serial port.
i have events that get the data and hold it in a buffer async from the main logic.
i have other code that does sleep() and checks the buffer for the needed data.
so the sleep use does allow my code to wait for the serial port to get the data and for my serial event to fetch it.
due to the data i can not just fire on a new char, i have to wait for a string of text and a newline to arrive.
figuerres said:obrienslalom said:*snip*not sure i would go THAT far...
example code for an app that gets text from a serial port.
i have events that get the data and hold it in a buffer async from the main logic.
i have other code that does sleep() and checks the buffer for the needed data.
so the sleep use does allow my code to wait for the serial port to get the data and for my serial event to fetch it.
due to the data i can not just fire on a new char, i have to wait for a string of text and a newline to arrive.
And you can't fire an event on a newline?
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.