You can :
1 - Run a thread in background that keep listening if there is any new process started / closed .
2 - once it gets started for example , you start a new Timer which will end when that process is closed.
3 - You can also get a little bit advanced , check if the Process has an Opened Window Handle , if it has it then check it's state if its minimized = pause the Timer and if its not then resume the timer associated to it .
you can ofcours use winapi for that for example :
IntPtr hwnd = yourProc.MainWindowHandle ; // this will gets you the process's main window handle .
// to get the window state using winapi :
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
// WINDOWPLACEMENT structure :
private struct WINDOWPLACEMENT
{
public int length;
public int flags;
public int showCmd; // this one is what you will need to check if minimized / maximized ..etc
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}
// showCmd possible cases (to compare the results if GetWindowPlacement returned true ) :
const int SW_HIDE = 0;
const int SW_SHOWNORMAL = 1;
const int SW_NORMAL = 1;
const int SW_SHOWMINIMIZED = 2;
const int SW_SHOWMAXIMIZED = 3;
const int SW_MAXIMIZE = 3;
const int SW_SHOWNOACTIVATE = 4;
const int SW_SHOW = 5;
const int SW_MINIMIZE = 6;
const int SW_SHOWMINNOACTIVE = 7;
const int SW_SHOWNA = 8;
const int SW_RESTORE = 9;
that's just to get you started somewhere hope it helps .