I am currently having trouble with a System.Threading.Timer when deploying my Windows Service to a Win2k3 Server. It works just fine ticking every second (overkill for debugging purposes) on my local machine when I install it, but after I install it to the server, the service starts successfully then never fires the timer event once. Has anyone run into a situation similar to this before? Most of my research has turned up issues that were apparently prevalent in .NET 1.1 from forever ago. Thanks for your time and help.
protected override void OnStart(string[] args)
{
int interval = Int32.Parse(ConfigurationManager.AppSettings["SleepTime"]) * 1000;
TimerCallback cb = new TimerCallback(ProcessTimerEvent);
QueueWorker worker = new QueueWorker();
workTimer = new Timer(cb, worker, interval, 1000);
}
private static void ProcessTimerEvent(object obj)
{
if (obj is QueueWorker)
{
QueueWorker qw = (QueueWorker)obj;
qw.doWork();
}
}
class QueueWorker
{
public void doWork()
{
// work happening here
}
}
UPDATE:
I've found that it has something to do with the user that the service needs to run as. When the service runs as System, the threads work great. Anyone know what permissions are needed for a user to be able to run the threads? I've tried using the "Act as part of the operating system" in the local security settings, but that just causes the service to start up then immediately fail when logged in as the user I added.
SleepTime
on the server? Other option: useSystem.Timers.Timer
instead. – ligosConsole.WriteLine
. And, sorry to ask stupid questions,SleepTime
is 1000 milliseconds = 1 second, right? – ligos