Reputation: 349
If i want my application to do something every 2hr (eg. pop up a message), how do i do that?
Do i program that set of code under onLoad() or somewhere else?
Upvotes: 1
Views: 2250
Reputation: 78447
Assuming WinForms.
You should use Windows Timer Class
Drag and drop timer component to your form.
Set interval to 7200000 (2 * 60 * 60 * 1000) milliseconds.
Subscribe to Tick
event (the only event that this component has).
private void timer1_Tick(object sender, EventArgs e)
{
MessageBox.Show("Example");
}
The code inside of timer will be triggered every 2 hours, if UI thread is not blocked.
Upvotes: 4