tags:

views:

19

answers:

2

I basically want a dispatcher timer object to only execute once.

So I have the basic code:

DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 4);
dispatcherTimer.Start();

Then inside the click event:

private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            this.Visibility = System.Windows.Visibility.Visible;
            // Now stop timer execution.. or kill the timer object
        }

How can I stop the timer or kill off the object after this execution?

+1  A: 
private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            this.Visibility = System.Windows.Visibility.Visible;
            (sender as DispatcherTimer).Stop();
        }
JL
A: 
private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            this.Visibility = System.Windows.Visibility.Visible;
            var dispatcherTimer = (DispatcherTimer)sender;
            dispatcherTimer.Stop();
        }     
Mark