我有一个应用程序,我想隐藏而不是关闭以便在后台运行。如果我隐藏它,当我重新启动应用程序时,如何在取消隐藏/重新激活当前正在运行的应用程序时终止新实例?我可以终止当前实例;
string currPrsName = Process.GetCurrentProcess().ProcessName;
//Get the name of all processes having the same name as this process name
Process[] theProcessWithThisName = Process.GetProcessesByName(currPrsName);
if (theProcessWithThisName.Length > 1)
{
string message = "'" + currPrsName + ".exe'" + " is already running.\nOperation canceled";
string caption = "ALREADY RUNNING";
MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(0); //Terminate this instance
}
我尝试了各种方法来取消隐藏应用程序,但均未成功。