Thursday, March 31, 2011

How do I maximize an application first instance when trying to start a new one

Hello, I would like to limit an application to having only one instance running on a machine. So far I have this :

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());
}

And it exits, but is there a way to maximise the first instance before this one closes?

From stackoverflow

0 comments:

Post a Comment