View Single Post
Old Mar 29th, 2008, 8:30 AM   #6
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 647
Rep Power: 4 OpenLoop is on a distinguished road
Re: scheduled events

Create a timer in your class:
c# Syntax (Toggle Plain Text)
  1. public partial class Form1 : Form
  2. {...
  3. Timer timer;
Initialize the timer in the class constructor:
c# Syntax (Toggle Plain Text)
  1. public Form1()
  2. {
  3. InitializeComponent();
  4. ...
  5. timer = new Timer();
  6. timer.Interval = 100; //calls the fuction specified below every 100ms (1/10 sec)
  7. timer.Tick += new EventHandler(CheckTime); //specify function to call every tick
  8. timer.Start(); //start the timer
  9. ...

create the function to be called every tick and put Chris's code in it:
c# Syntax (Toggle Plain Text)
  1. void CheckTime(object sender, EventArgs e)
  2. {
  3. DateTime theDate = DateTime.Parse("27 Mar 2008 00:26:00");
  4. if (DateTime.Now => theDate)
  5. {
  6. MessageBox.Show((DateTime.Now).ToString());
  7. timer.Stop(); //if the event is no longer to be checked for, stop the timer
  8. }
  9. }
OpenLoop is offline   Reply With Quote