123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Diagnostics;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- namespace prBrowser
- {
- internal static class Program
- {
- [STAThread]
- private static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(defaultValue: false);
- Process instance = RunningInstance();
- if (instance == null)
- {
- Application.Run(new MainForm());
- }
- else
- {
- HandleRunningInstance(instance);
- }
- }
- private static Process RunningInstance()
- {
- Process current = Process.GetCurrentProcess();
- Process[] processes = Process.GetProcessesByName(current.ProcessName);
- Process[] array = processes;
- foreach (Process process in array)
- {
- if (process.Id != current.Id && Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
- {
- return process;
- }
- }
- return null;
- }
- private static void HandleRunningInstance(Process instance)
- {
- ShowWindowAsync(instance.MainWindowHandle, 3);
- 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);
- }
- }
|