C# 在尝试启动新的应用程序时,如何最大化应用程序的第一个实例

C# 在尝试启动新的应用程序时,如何最大化应用程序的第一个实例,c#,multithreading,C#,Multithreading,我想限制一个应用程序在一台机器上只运行一个实例。到目前为止,我有: Mutex m = new Mutex(true, Name, out IsOwned); if (!IsOwned) { string message = "There is already a copy of the application '" + Name + "' running. Please close that application before starting a

我想限制一个应用程序在一台机器上只运行一个实例。到目前为止,我有:

Mutex m = new Mutex(true, Name, out IsOwned);

if (!IsOwned)
{
    string message = "There is already a copy of the application '" +
        Name + 
        "' running. Please close that application before starting a new one.";

    MessageBox.Show(message, "Error", 
        MessageBoxButtons.OK, MessageBoxIcon.Information);

    Environment.Exit(0);
}
else
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}

它会退出,但有没有办法在第一个实例关闭之前最大化第一个实例?

这不是处理应用程序多个实例的方法。公认的做法是只切换到应用程序的运行实例

也就是说,您可以轻松创建从WindowsFormsApplicationBase(在Microsoft.VisualBasic命名空间中)派生的类。此答案概述了您将如何执行此操作,并指出您需要单个实例,以及如何处理尝试运行新实例时发生的情况: