Click here to Skip to main content
15,905,420 members
Home / Discussions / C#
   

C#

 
QuestionList of applications Pin
-Yoyosh-12-Oct-06 2:16
-Yoyosh-12-Oct-06 2:16 
AnswerRe: List of applications Pin
Alper Camel12-Oct-06 2:26
Alper Camel12-Oct-06 2:26 
QuestionEMF file getting deleted after creation Pin
cppandey2312-Oct-06 1:36
cppandey2312-Oct-06 1:36 
QuestionEMF plotting API Pin
cppandey2312-Oct-06 1:32
cppandey2312-Oct-06 1:32 
Questionuerasable lines Pin
ssoffline12-Oct-06 0:37
ssoffline12-Oct-06 0:37 
AnswerRe: uerasable lines Pin
Guffa12-Oct-06 2:44
Guffa12-Oct-06 2:44 
GeneralRe: uerasable lines Pin
ssoffline12-Oct-06 3:42
ssoffline12-Oct-06 3:42 
GeneralRe: uerasable lines Pin
J4amieC12-Oct-06 3:59
J4amieC12-Oct-06 3:59 
AnswerRe: uerasable lines Pin
Guffa12-Oct-06 7:49
Guffa12-Oct-06 7:49 
GeneralRe: uerasable lines Pin
ssoffline12-Oct-06 9:08
ssoffline12-Oct-06 9:08 
AnswerRe: uerasable lines Pin
Guffa13-Oct-06 7:26
Guffa13-Oct-06 7:26 
GeneralRe: uerasable lines Pin
ssoffline13-Oct-06 19:29
ssoffline13-Oct-06 19:29 
AnswerRe: uerasable lines Pin
Guffa14-Oct-06 1:34
Guffa14-Oct-06 1:34 
GeneralRe: uerasable lines Pin
ssoffline14-Oct-06 9:54
ssoffline14-Oct-06 9:54 
QuestionEmail verification Pin
Parmenio11-Oct-06 23:51
Parmenio11-Oct-06 23:51 
AnswerRe: Email verification Pin
Rob Philpott12-Oct-06 2:20
Rob Philpott12-Oct-06 2:20 
GeneralRe: Email verification Pin
Parmenio12-Oct-06 20:24
Parmenio12-Oct-06 20:24 
QuestionSingle instance of application Pin
Parshant Verma11-Oct-06 23:50
Parshant Verma11-Oct-06 23:50 
AnswerRe: Single instance of application Pin
Andrei Ungureanu12-Oct-06 0:17
Andrei Ungureanu12-Oct-06 0:17 
GeneralRe: Single instance of application Pin
User 665812-Oct-06 2:15
User 665812-Oct-06 2:15 
AnswerRe: Single instance of application Pin
Stefan Troschuetz12-Oct-06 0:20
Stefan Troschuetz12-Oct-06 0:20 
AnswerRe: Single instance of application Pin
engsrini12-Oct-06 3:18
engsrini12-Oct-06 3:18 
This is the code your looking for.

[STAThread]
        static void Main()
        {
            //Get the running instance.
            Process instance = RunningInstance();
            if (instance == null)
            {
                //There isn't another instance, show our form.

                    Application.Run(new AteGui(splashScrn));            
                
            }
            else
            {
                //There is another instance of this process.
                HandleRunningInstance(instance);
            }
        }

<big>Helper Functions and DLL imports</big>
 /// <summary>
        /// Property to set the visible status of the Tutorial Button
        /// </summary>
        public static Process RunningInstance()
        {
            Process current = Process.GetCurrentProcess();
            Process[] processes = Process.GetProcessesByName(current.ProcessName);

            //Loop through the running processes in with the same name
            foreach (Process process in processes)
            {
                //Ignore the current process
                if (process.Id != current.Id)
                {
                    //Make sure that the process is running from the exe file.
                    if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") ==
                    current.MainModule.FileName)
                    {
                        //Return the other process instance.
                        return process;
                    }
                }
            }

            //No other instance was found, return null.
            return null;
        }


        public static void HandleRunningInstance(Process instance)
        {
            //Make sure the window is not minimized or maximized
            ShowWindowAsync(instance.MainWindowHandle, WS_SHOWNORMAL);

            //Set the real intance to foreground window
            SetForegroundWindow(instance.MainWindowHandle);
        }

         [DllImport("User32.dll")] 

        private static extern bool ShowWindowAsync(
         IntPtr hWnd, int cmdShow);
         [DllImport("User32.dll")] private static extern bool
         SetForegroundWindow(IntPtr hWnd);
         private const int WS_SHOWNORMAL = 1;

GeneralRe: Single instance of application Pin
mav.northwind12-Oct-06 10:20
mav.northwind12-Oct-06 10:20 
Questiongetting fields of a table Pin
saqib8211-Oct-06 23:46
saqib8211-Oct-06 23:46 
AnswerRe: getting fields of a table Pin
quiteSmart12-Oct-06 2:27
quiteSmart12-Oct-06 2:27 

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

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