Exemple #1
0
 private void btnStopStart_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtTimeIntervalInMiliseconds.Text) == false)
     {
         if (mTimer1 != null)
         {
             //mTimer1.ReleaseSemaphore();
             //System.Threading.Thread.Sleep(10);// Ensure callbacks are drained
             //while (mTimer1.IsReady() == false) ;
             if (mTimer1.mTimerId != 0)
             {
                 mTimer1.Stop();
             }
             btnStopStart.Text = "Start";
             mTimer1           = null;
             fStart            = false;
         }
         else
         {
             try
             {
                 delay = Convert.ToInt32(txtTimeIntervalInMiliseconds.Text);   // In milliseconds. 10 = 1/100th second.
             }
             catch (Exception ex)
             {
                 return;
             }
             mTimer1           = new AccurateTimer(this, new Action(TimerTick1), delay);
             btnStopStart.Text = "Stop";
             fStart            = true;
         }
     }
 }
Exemple #2
0
 private void TimerTick1()
 {
     //if (mTimer1.mTimerId != 0)
     {
         // Put your first timer code here!
         Application.DoEvents();
         //System.Threading.Thread.Sleep(10);// Ensure callbacks are drained
         DateTime dt          = DateTime.Now;
         string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", dt.Hour, dt.Minute, dt.Second, dt.Millisecond);
         lstbxElapsedTime.Items.Add(elapsedTime);
         //mTimer1.ReleaseSemaphore();
         if (fStart == true)
         {
             mTimer1 = new AccurateTimer(this, new Action(TimerTick1), delay);
         }
     }
 }