取消隐藏并激活隐藏的表单/应用程序

时间:2013-01-20 22:25:13

标签: c# winforms

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

终止当前实例
        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
        }

我尝试了各种方法取消隐藏应用程序但没有成功。

1 个答案:

答案 0 :(得分:0)

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