You are going to have to poll to see if the parent application is still running.
One way to do this is setting up when an application was run by configuring audit process tracking in Windows. The following links might get you started:
Audit process tracking
How can I track what programs come and go on my machine?
The process tracking will create entries in the Windows event log which you can then access using C++, C# &/or VB.Net. You can use these logs to see if the Parent application is running.
Edit:
If you have access to the C++ codebase you could try to catch the exception when the parent app crashes or closes, eg:
Application.ThreadException += new ThreadExceptionEventHandler(ApplicationThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ApplicationUnhandledException);
private void ApplicationThreadException(object sender, ThreadExceptionEventArgs e)
{
//Write to a File, Registry, Database flagging the application has crashed
}
private void ApplicationUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
//Write to a File, Registry, Database flagging the application has crashed
}
private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
{
//Write to a File, Registry, Database flagging the application has closed
}
Otherwise you will have to poll to see if the Parent application is listed in the Process Manager, eg:
StringBuilder sb = new StringBuilder();
ManagementClass MgmtClass = new ManagementClass("Win32_Process");
foreach (ManagementObject mo in MgmtClass.GetInstances())
{
sb.Append("Name:\t" + mo["Name"] + Environment.NewLine);
sb.Append("ID:\t" + mo["ProcessId"] + Environment.NewLine);
sb.Append(Environment.NewLine);
}
If its not listed, close the child application.