Check for another instance og execute

  • Thread starter Thread starter =?iso-8859-1?B?wWf6c3Q=?=
  • Start date Start date
?

=?iso-8859-1?B?wWf6c3Q=?=

Hi
I would like to enforce users of my program not beeing
able to run more than one instance of it at any given
time.

For example, on start, check if there are any instances of
the program running and if soo bail out ( exit ).

Any hints anyone?
 
Hi
I would like to enforce users of my program not beeing
able to run more than one instance of it at any given
time.

For example, on start, check if there are any instances of
the program running and if soo bail out ( exit ).

Any hints anyone?

read more about Mutex() class.
 
I tried a RoundAbout Method but it works....

public static Process pcheck() //function to return an existing process or
null if no process is running
{
Process current = Process.GetCurrentProcess();
Process[] allProcess = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in allProcess)
{
if(process.Id !=current.Id)
{
if (Assembly.GetExecutingAssembly().Location.Replace("/","\\")
== current.MainModule.FileName)
{
return process;
}
}
}
return null;
}

// in ur main do this

static void Main()
{
Process ptry = pcheck();
if (ptry!=null)
{
//alert user and exit
// SendMessage(FindWindow(0,"Net Sender"),786,0,0); // i did this inorder
to bring my application to focus which is in iconic mode
}
else
{
Application.Run(new frmname());
}
}
 
Back
Top