Perwyl Liu
Perwyl Liu

Reputation: 349

Visual Studio 2008, Timer, c#

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

Answers (3)

Alex Aza
Alex Aza

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

Nik
Nik

Reputation: 7273

Use the Timer class and set it up when the application starts.

Upvotes: 1

Rami Alshareef
Rami Alshareef

Reputation: 7140

Check the Timer Control and event Tick

Timer.Tick - MSDN

Upvotes: 3

Related Questions