csharpula csharp wrote:
Hello I am using the ManualResetEvent WaitOne and I have a question:
I use it in order to wait for sometimeout and if some function wasn't
activated by other process I should activate it myself.
How can I know if some function was called during the Wait?
Thanks!
*** Sent via Developersdex http://www.developersdex.com ***
Here are some sample code from MSDN :
class WaitOne
{
static AutoResetEvent autoEvent = new AutoResetEvent(false);
static void Main()
{
Console.WriteLine("Main starting.");
ThreadPool.QueueUserWorkItem(
new WaitCallback(WorkMethod), autoEvent);
// Wait for work method to signal.
if(autoEvent.WaitOne(1000, false))
{
Console.WriteLine("Work method signaled.");
}
else
{
Console.WriteLine("Timed out waiting for work " +
"method to signal.");
** You can set the event here by yourself **
}
Console.WriteLine("Main ending.");
}
static void WorkMethod(object stateInfo)
{
Console.WriteLine("Work starting.");
// Simulate time spent working.
Thread.Sleep(new Random().Next(100, 2000));
// Signal that work is finished.
Console.WriteLine("Work ending.");
((AutoResetEvent)stateInfo).Set();
}
}