public Process GetInstanceJavaProcess()
{
Process instanceProcess = null;
try {
// try to find matching process name
/*
-- this was supposed to support finding running instance again when AEM manager was stopped
-- but this does not seem to work any longer, and even creates performance issues on some machines
-- so, deactivate it for now
foreach (Process process in Process.GetProcesses()) {
if (process.MainWindowTitle.Equals(this.Name)
|| process.MainWindowTitle.EndsWith("\\" + this.Name + ".lnk")) {
instanceProcess = process;
break;
}
}
*/
// if none found use process associated with instance
if (instanceProcess == null) {
instanceProcess = this.JavaProcess;
}
// check if process is still alive
if (instanceProcess != null) {
if (instanceProcess.HasExited) {
instanceProcess = null;
mJavaProcess = null;
}
else {
instanceProcess.Refresh();
}
}
}
catch (InvalidOperationException ex) {
mLog.Warn("Error checking process state of '" + this.Name + "'.", ex);
instanceProcess = null;
mJavaProcess = null;
}
return instanceProcess;
}