Running a sleeping thread in .NET.

if threadA is sleeping, how will another threadB threadA start? Give an example, if possible.

+5
source share
2 answers

Instead of sleeping, you want to create an EventWaitHandle and use WaitOne with a timeout.

When you want the thread to wake up earlier, you simply set up an event for signaling.

First create EventWaitHandle:

wakeUpEvent = new EventWaitHandle(false, EventResetMode.ManualReset);

Then in your thread:

wakeUpEvent.WaitOne(new TimeSpan(1, 0, 0));

When the main program wants to wake the thread earlier:

wakeUpEvent.Set();

. auto reset reset. reset , , WaitOne , . , , .

+6

WaitObject , Set . WaitHandle.WaitOne.

, .

+1

All Articles