Main thread of application is doing some work.
There also exists a timer, which should every 10 minutes call some method which should run asynchronous.
Could you please give me a good example how to organize this?
I would not recommend using an explicit thread with a loop and sleep. It's bad practice and ugly. There are timer classes for this purpose:
If this is not a GUI app, then you can use System.Threading.Timer to execute code on a different thread periodically.
If this is a WinForms/WPF app take a look at System.Windows.Forms.Timer and System.Windows.Threading.DispatcherTimer respectively. These are handy because they execute their code on the GUI thread, thus not needing explicit Invoke
calls.
The links also contain examples for each one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With