I've created a Windows Service called ProxyMonitor and I'm currently at the stage where the service is installs and uninstall's the way I want it.
So I execute the application like so:
C:\\Windows\\Vendor\\ProxyMonitor.exe /install
Pretty self explanatory, and then I got to services.msc
and and start the service, but when I do this I get the following message:
The Proxy Monitor Service on Local Computer started and then stopped. Some services stop automatically if there is no work to do, For example, The performance Logs and Alerts Services
My code looks like so:
public static Main(string[] Args)
{
if (System.Environment.UserInteractive)
{
/*
* Here I have my install logic
*/
}
else
{
ServiceBase.Run(new ProxyMonitor());
}
}
And then within ProxyMonitor class I have:
public ProxyMonitor()
{
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
ProxyEventLog.WriteEntry("ProxyMonitor Started");
running = true;
while (running)
{
//Execution Loop
}
}
and onStop()
I just change the running
variable to false
;
What would I need to do to make the Service constantly active, as I would need to be monitoring the network I need to trace changes etc.
Update: 1
protected override void OnStart(string[] args)
{
base.OnStart(args);
ProxyEventLog.WriteEntry("ProxyMonitor Started");
Thread = new Thread(ThreadWorker);
Thread.Start();
}
Within the ThreadWorker
I have ProxyEventLogger.WriteEntry("Main thread entered")
which does not get fired.