BackGround Thread with timer for application level-WPF Application
c#, multithreading, scheduler, timer, wpf
Solution
If you want to execute an action periodically in a WPF application you can use the DispatcherTimer class.
Put your code as the handler of the `Tick` event and set the `Interval` property to whatever you need. Something like:
DispatcherTimer dt = new DispatcherTimer();
dt.Tick += new EventHandler(timer_Tick);
dt.Interval = new TimeSpan(1, 0, 0); // execute every hour
dt.Start();
// Tick handler
private void timer_Tick(object sender, EventArgs e)
{
// code to execute periodically
}
Problem
I have a wpf application(No MVVM), this application requires several background thread(Runs with specific time interval). These thread should be on Application Level i.e. if user is on any WPF Window, these threads should be active. Basically these thread will are using external resources so locking is also required. Kindly tell me the best way to do this.