I am using a DispatchTimer to do something every second, how can I make it do Something for a set amount of time say 1 minute or 2 minutes? Do I need anther nested DispatcherTimer?
My code is below
System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
private void StartButton_Click(object sender, RoutedEventArgs e)
{
TimeSpan interval;
interval = (TimeSpan)intervalPicker.Value;
dt.Interval = interval;
dt.Tick += new EventHandler(dt_Tick);
dt.Start();
}
void dt_Tick(object sender, EventArgs e)
{
//Do Something
}
I would appreciate if you could help me thanks.
Use the
Stopwatchclass: