0

我有一个应用程序,我想隐藏而不是关闭以便在后台运行。如果我隐藏它,当我重新启动应用程序时,如何在取消隐藏/重新激活当前正在运行的应用程序时终止新实例?我可以终止当前实例;

        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
        }

我尝试了各种方法来取消隐藏应用程序,但均未成功。

4

1 回答 1

0

我认为有一个很好的演练可以回答你所有的问题。看看: http: //www.codeproject.com/Articles/32908/C-Single-Instance-App-With-the-Ability-To-Restore

于 2013-01-20T23:44:23.720 回答