• システム開発に関わる内容をざっくりと書いていく

二重起動検知

二重起動を検知して最小化されている場合は表示する

Mutex mutex = new Mutex(true, "MainMenu", out createdNew);

if (!createdNew)
{            	
    var proc = Process.GetCurrentProcess();
    var otherProc = Process.GetProcessesByName(proc.ProcessName)
                           .Where(v => v.Id != proc.Id)
                           .FirstOrDefault();
    if (otherProc != null)
    {
        IntPtr hWnd = otherProc.MainWindowHandle;
        if (IsIconic(hWnd))
        {
            ShowWindowAsync(hWnd, SW_RESTORE);
        }
        SetForegroundWindow(hWnd);
        return;
    }
}