Re: Waiting for a timer event in a console application?
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 11/23/04
- Next message: Ian Griffiths [C# MVP]: "Re: Why "Specified cast is not valid" error?"
- Previous message: Mike Kitchen: "Re: new to C#, look for a good book..."
- In reply to: Kurt: "Re: Waiting for a timer event in a console application?"
- Next in thread: Willy Denoyette [MVP]: "Re: Waiting for a timer event in a console application?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 23 Nov 2004 08:56:13 -0000
Kurt <kurbylogic@hotmail.com> wrote:
> Rather then Sleep, wake, check enabled, Sleep, wake, check enabled,
> etc..
> You can use a ManualResetEvent to signal the main thread when you have
> disabled the timer and thread will only need to wake when the event is
> signaled
>
> class Foo
> {
> ManualResetEvent mExitEvent = new ManualResetEvent(false);
> Timer mTimer = new Timer(1000);
> ...
> void Run()
> {
> ...
> Timer.Start();
> mExitEvent.WaitOne();
> }
> void TimerEvent(object source, ElapsedEventArgs e)
> {
> ...
> mTimer.Stop();
> mExitEvent.Set();
> }
> }
Alternatively, just use Monitor.Wait and Monitor.Pulse.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Ian Griffiths [C# MVP]: "Re: Why "Specified cast is not valid" error?"
- Previous message: Mike Kitchen: "Re: new to C#, look for a good book..."
- In reply to: Kurt: "Re: Waiting for a timer event in a console application?"
- Next in thread: Willy Denoyette [MVP]: "Re: Waiting for a timer event in a console application?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|