Windows Phone Developers

Wednesday, December 23, 2009

Check Multiple Instances of an Application using C#

How to check if multiple instances of the application are running using C# (.NET)

Here is a simple code to check if multiple instances of current application are running in the machine using System.Diagnostics

private static void check_application_process_instances()


Process[] oProcess;

String sModuleName;

String sProcessName;

sModuleName = Process.GetCurrentProcess().MainModule.ModuleName;

sProcessName = System.IO.Path.GetFileNameWithoutExtension(sModuleName);

oProcess = Process.GetProcessesByName(sProcessName);

if (oProcess.Length > 1 )


MessageBox.Show("More than one instance is running!");



Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment:

  1. How do I find Process.GetProcessesByName.
    I have Visual Studio 2008 and if I import system.diagnostics and use try to find GetProcessesByName, the only options I can see are Process.GetCurrentProcess and Process.GetProcessById. What am I missing. Everyone seems to have Process.GetProcessesByName?