March 2004
Intermediate to advanced
560 pages
26h 47m
English
using System;
using System.Threading;
namespace Samples
{
public class TimerSample
{
public static AutoResetEvent are =
new AutoResetEvent(false);
public static Timer t = null;
public const int number = 9;
public class StateHolder
{
public int counter = 0;
}
static void CallMe(Object s)
{
StateHolder sh = (StateHolder) s;
Console.WriteLine("{0}: {1}",
sh.counter++, DateTime.Now);
if(sh.counter > number)
{
t.Dispose(are);
}
}
public static void Main()
{
StateHolder sh = new StateHolder();
TimerCallback tcb =
new TimerCallback(CallMe);
t = new Timer(
tcb, sh, 1000, 1000);
are.WaitOne();
}
}
}
0: 24/06/2003 3:26:06 AM 1: 24/06/2003 3:26:07 AM 2: 24/06/2003 3:26:08 AM 3: 24/06/2003 3:26:09 AM 4: 24/06/2003 3:26:10 AM 5: 24/06/2003 ...
Read now
Unlock full access