Click here to Skip to main content
15,896,154 members
Home / Discussions / C#
   

C#

 
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 
QuestionHow to differentiate the virtual printer Pin
Brosis11-Oct-06 23:25
Brosis11-Oct-06 23:25 
Questionself launcher deployment using windows installer Pin
Praveen Raghuvanshi11-Oct-06 22:53
professionalPraveen Raghuvanshi11-Oct-06 22:53 
AnswerRe: self launcher deployment using windows installer Pin
Alper Camel12-Oct-06 2:34
Alper Camel12-Oct-06 2:34 
Questiongettting table name Pin
saqib8211-Oct-06 22:33
saqib8211-Oct-06 22:33 
AnswerRe: gettting table name Pin
AETaylor11-Oct-06 22:37
AETaylor11-Oct-06 22:37 
AnswerRe: gettting table name Pin
Bright Zhang11-Oct-06 23:16
Bright Zhang11-Oct-06 23:16 
AnswerRe: gettting table name Pin
quiteSmart12-Oct-06 2:25
quiteSmart12-Oct-06 2:25 
Questionhow to create webboard for c# Pin
isis_preaw11-Oct-06 22:29
isis_preaw11-Oct-06 22:29 
QuestionEntering Next Character in the Text Box using VB 6 Pin
ghelai_cute11-Oct-06 22:28
ghelai_cute11-Oct-06 22:28 
AnswerRe: Entering Next Character in the Text Box using VB 6 Pin
mav.northwind12-Oct-06 10:23
mav.northwind12-Oct-06 10:23 
QuestionWMI enabl disable in c# Pin
Tauseef A11-Oct-06 22:26
Tauseef A11-Oct-06 22:26 
QuestionGood book referance on User Controls Design Pin
eyalRF11-Oct-06 22:19
eyalRF11-Oct-06 22:19 
GeneralRe: Good book referance on User Controls Design Pin
Bright Zhang11-Oct-06 23:19
Bright Zhang11-Oct-06 23:19 
GeneralRe: Good book referance on User Controls Design Pin
Berlus12-Oct-06 6:46
Berlus12-Oct-06 6:46 

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.