One Instance of two application

  • Thread starter Thread starter LirenZhao
  • Start date Start date
L

LirenZhao

I use two application in my software(a.exe / b.exe)
I need only one Instance of two application , who can help me?
 
Move all logic from "b" application into "a" or implement "b"
application as the assembly and add a reference to it in the "a"
application.
 
If I understand your question right, you want to be able to run only one
instance of any of two given applications at once. I also assume you are the
author of both applications and can modify the source. Using Mutex is the
possible solution to accomplish this.
Both applications should try to grab Mutex aj start, and if it is already
given to another running instance, close themselves.
Refer to
http://msdn.microsoft.com/library/d...tml/frlrfsystemthreadingmutexmemberstopic.asp
for details.
 
Thanks Lebesgue.

Lebesgue said:
If I understand your question right, you want to be able to run only one
instance of any of two given applications at once. I also assume you are
the
author of both applications and can modify the source. Using Mutex is the
possible solution to accomplish this.
Both applications should try to grab Mutex aj start, and if it is already
given to another running instance, close themselves.
Refer to
http://msdn.microsoft.com/library/d...tml/frlrfsystemthreadingmutexmemberstopic.asp
for details.
 
I used the same code in my two application,but it seems does not work.

static void Main()
{
System.Threading.Mutex mutex = new System.Threading.Mutex(false); // new
System.Threading.Mutex(false,"Some string here");
bool Running = !mutex.WaitOne();
if (! Running)
{
Application.Run(new Form1());
}
else
{
MessageBox.Show("Already Running");
}
}
 
Back
Top