only My site

Friday, February 25, 2011

WPF : Restrict Multiple Instance

protected override void OnStartup(StartupEventArgs e){

// Get Reference to the current Process

Process thisProc = Process.GetCurrentProcess();

// Check how many total processes have the same name as the current one

if (Process.GetProcessesByName(thisProc.ProcessName).Length > 1)

{

// If ther is more than one, then it is already running.

MessageBox.Show("Another Instance is already running.");

Application.Current.Shutdown();

return;

}

base.OnStartup(e);

}

No comments: