Hi,
I have encountered a problem. I am checking if my application "testApp" is found in the ApplicationTab in TaskManager. The code below works 100%.
But the problem is this when you just "rightclick" with the mouse on the "testApp" in the Taskbar, this code will produce the file and tell that it no longer was found in the ApplicationTab.
This happens only when you "rightclick" the "testApp" in the Taskbar without doing anything else.
I wonder why this happens as I need to check that "testApp" is still running all the time?
using System.Diagnostics;
private void checkConnection_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
bool applicationFound = false;
foreach (Process clsProcess in Process.GetProcesses())
{
String getName = clsProcess.MainWindowTitle.ToString().ToLower();
if (getName.IndexOf("testapp") != -1)
{
applicationFound = true; break;
}
}
if (applicationFound == false)
{
FileStream hr = new FileStream("C:/test.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamWriter file1 = new StreamWriter(hr);
file1.WriteLine("Process not found..."); file1.Close(); hr.Close();
}
Thread.Sleep(1000);
}
}