I have written an windows service application in c# to find wether the applications configured are running in the process or not. For instance if I have configured OUTLOOK and checking in the application process list if outlook is open/closed if my application didnt find OUTLOOK in process list then it emails me saying your application OUTLOOK is either closed or crashed.
When I am trying to run this in code it is sending email only if OUTLOOK is closed but when I am running using Service it is sending an email even if OUTLOOK is running.
Can anyone please explian me why my Service is not able to recognize applications in application process list.
public void GetListofApplications(List<string> applicationsInConfig)
{
if (AppsInActive.Count > 0)
{
AppsInActive.Clear();
}
StringBuilder sb = new StringBuilder();
foreach (Process p in Process.GetProcesses("."))
try
{
if (p.MainWindowTitle.Length > 0)
{
APPsInProcess.Add(p.ProcessName.ToString());
}
}
catch(Exception ex)
{
Logger.Log("Exception in Finding Process" + ex);
}
foreach (var application in applicationsInConfig)
{
if (APPsInProcess.Contains(application))
{
AppsActive.Add(application);
}
else
{
AppsInActive.Add(application);
}
}
foreach (var item in AppsInActive)
{
Logger.Log("Following application is either crashed/closed :" + item);
}
Helper.EmailSetup setup = new Helper.EmailSetup();
setup.ApplicationFailedEmailSetup(AppsInActive, DateTime.Now);
}
try to check OUTLOOK in this way
Just try at first find only outlook, if this doesn’t help, comment please