I got my timer to work. But when it fails, it is supposed to send out a message. I am testing the service on a machine that should "fail" every time. I start the service, it calls the sendText routine several times. No messages are sent until I STOP the service. Then a bunch of messages come rolling in. Not sure what I need to put into the code to allow the machine to process and send the messages?? Even the start/stop messages don't seem to process until I stop the service.
C#:
protected override void OnStart(string[] args)
{
timer1 = new System.Timers.Timer(60000);
timer1.Elapsed += checkTaskManager ;
timer1.Start();
DateTime dtNow = DateTime.Now;
sendText("Service is started - " + dtNow.ToString(), "ICES Service is started. ");
}
protected override void OnStop()
{
timer1.Stop();
DateTime dtNow = DateTime.Now;
sendText("Service is stopped - " + dtNow.ToString(), "ICES Service is stopped. ");
}
private void checkTaskManager(object sender, ElapsedEventArgs e)
{
string sCheckVal = "Java";
Debugger.Break();
if (bChecking == false && sCheckVal != "")
{
TaskMgrCheck tskCheck = new TaskMgrCheck();
//read the string to check from either a text file or a command line switch.
int iCount = tskCheck.checkTaskMgr(sCheckVal);
DateTime dtNow = DateTime.Now;
//MessageBox.Show("I found " + iCount.ToString() + " instances of \"" + sCheckVal + "\"");
if (iCount < 3 )
{
//Set a bChecking value while I am working here so I don't keep sending notifications.
bChecking = true;
string sMachineName = System.Environment.MachineName.ToString();
string sMessage = "Production ICES is not running on " + sMachineName +
" server. There are only " + iCount.ToString() +
" instances of \"" + sCheckVal + "\" running.";
sendText("ICES Prod is Down - " + dtNow.ToString(), sMessage);
}
bChecking = false;
}
}