Skip to content

Instantly share code, notes, and snippets.

@begedin
Created May 7, 2013 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save begedin/5533011 to your computer and use it in GitHub Desktop.
Save begedin/5533011 to your computer and use it in GitHub Desktop.
Run single instance process from console.
[STAThread()]
static void Main(string[] args)
{
Console.Title = "Call App";
// hide the console window
setConsoleWindowVisibility(false, Console.Title);
// look for all running instances of the app
var runningProcessByName = Process.GetProcessesByName("notepad");
if (runningProcessByName.Length == 0)
{
Process.Start("notepad.exe");
}
else
{
SetForegroundWindow(Process.GetProcessById
(runningProcessByName.ElementAt(0).Id).MainWindowHandle);
ShowWindow(Process.GetProcessById
(runningProcessByName.ElementAt(0).Id).MainWindowHandle, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment