Exemplo n.º 1
0
        public static void CheckSingleByProcessName()
        {
            string processName = Process.GetCurrentProcess().ProcessName;

            Process[] processesByName = Process.GetProcessesByName(processName);
            bool      flag            = processesByName != null && processesByName.Count <Process>() > 1;

            if (flag)
            {
                Process[] array = processesByName;
                for (int i = 0; i < array.Length; i++)
                {
                    Process process = array[i];
                    bool    flag2   = process.Id != Process.GetCurrentProcess().Id;
                    if (flag2)
                    {
                        SingleApp.HandleRunningInstance(process);
                    }
                }
                Environment.Exit(0);
            }
        }
Exemplo n.º 2
0
 private static void HandleRunningInstance(Process instance)
 {
     SingleApp.ShowWindowAsync(instance.MainWindowHandle, 1);
     SingleApp.SetForegroundWindow(instance.MainWindowHandle);
 }