V
VJ
I hope this is right forum for this...
I have the below block of code in my Main. When I compile in debug mode, I
get to run one instance only. When I compile in release mode, I get to run
more than one instance of my application. These are the first lines of my
application.. I tried to set the mutexName to a string or a GUID or the full
assembly name, still I can't get single Instance behaviour in Release mode
bool mutexWasCreated = false;
bool requestInitialOwnership = true;
string mutexName = "MyApp";
//System.Runtime.InteropServices.Marshal.GetTypeLibGuidForAssembly(System.Reflection.Assembly.GetExecutingAssembly()).ToString();
//System.Reflection.Assembly.GetExecutingAssembly().FullName;
System.Threading.Mutex m = new
Mutex(requestInitialOwnership,mutexName,out mutexWasCreated);
// If I put a log information here. I get True also..
try
{
if (mutexWasCreated)
{
m.ReleaseMutex();
}
else
{
MessageBox.Show("Application is already
running","MyApp",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
finally
{
m.Close();
}
// Code here calls Application.Run
I have the below block of code in my Main. When I compile in debug mode, I
get to run one instance only. When I compile in release mode, I get to run
more than one instance of my application. These are the first lines of my
application.. I tried to set the mutexName to a string or a GUID or the full
assembly name, still I can't get single Instance behaviour in Release mode
bool mutexWasCreated = false;
bool requestInitialOwnership = true;
string mutexName = "MyApp";
//System.Runtime.InteropServices.Marshal.GetTypeLibGuidForAssembly(System.Reflection.Assembly.GetExecutingAssembly()).ToString();
//System.Reflection.Assembly.GetExecutingAssembly().FullName;
System.Threading.Mutex m = new
Mutex(requestInitialOwnership,mutexName,out mutexWasCreated);
// If I put a log information here. I get True also..
try
{
if (mutexWasCreated)
{
m.ReleaseMutex();
}
else
{
MessageBox.Show("Application is already
running","MyApp",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
finally
{
m.Close();
}
// Code here calls Application.Run