Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Run Only One Copy Of Application

By , 25 Mar 2011
Rate this:
Please Sign up or sign in to vote.

Maybe this is helpful, it tries to switch to the first running instance:

namespace UltraSimple.Win
    static class Program
        public static extern bool SetForegroundWindow(IntPtr hWnd);
        static void Main()
            Process oProcess = Process.GetCurrentProcess();
            Process[] aoProcesses = Process.GetProcessesByName(oProcess.ProcessName);
            if (aoProcesses.Length > 1)
                      "The application \""
                    + oProcess.ProcessName
                    + "\" is already running.", "Ultrasimple");
                Program.SetForegroundWindow(aoProcesses[aoProcesses[0].Id == 
                        oProcess.Id ? 1 : 0].MainWindowHandle);


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author


Netherlands Netherlands
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pinmemberraj ch6-Jul-13 0:11 
GeneralReason for my vote of 5 The SetForgroundWindow is a nice fea... PinmemberRoy from Detroit12-Dec-11 4:52 
GeneralHave not done a perf mon on both of the solutions, but findi... Pinmemberzenwalker198516-Oct-11 4:05 
GeneralReason for my vote of 5 nice alternative Pinmembercharles henington22-Apr-11 6:07 
GeneralReason for my vote of 5 Reason for my vote of 5 Nice way to... PinmemberRK_DBA14-Apr-11 17:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 25 Mar 2011
Article Copyright 2011 by FDW
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid