Hopefully a simple DateTime problem.
I've got a windows service created in C# on .Net Framework 2.0, the
service uses a system timer to fire an event every second and compare
that against a known time to fire off a worker thread. All the
DateTime objects are using local time as the services are local to the
server.
DateTime runAt = DateTime.Parse( "4/24/2007 2:30:00 PM");
System.Timers.T imer _timer = new System.Timers.T imer();
protected override void OnStart(string[] args)
{
base.OnStart(ar gs);
_timer.Interval = 1000;
_timer.Elapsed += new ElapsedEventHan dler(timeElapse d);
_timer.Start();
}
void timeElapsed(obj ect sender, ElapsedEventArg s args)
{
if (DateTime.Compa re(runAt, DateTime.Now) ==
0)
{
// Spawn a new thread to do the cleanup
work
WorkerThread threadObj = new WorkerThread();
Thread workerThread = new Thread(new
ThreadStart(thr eadObj.BeginTas k));
workerThread.St art();
}
}
The problem is that the DateTime.Compar e never says that the two
DateTime objects match so the worker thread isn't created. I've
confirmed that the formats of the two datetime formats are the same
using an Event Log entry and they match perfectly.
Any ideas to why this happening are greatly appreciated.