Mutex issue on NT4 with 1.1 Framework

D

Dinsdale

I have recently added a mutex to the startup of an application to stop
users from opening multiple instances. Works great except the
application no longer works on NT4. The error I get is:

The Application has generated an exception that could not be handled.

Process id = 0x12b (299), Thread id = 0x100 (256)

To test my theory, I created a small windows form app and ran it with
no problems. I added the same mutex code to it and received the same
error as noted above.

I double checked in MSDN and it claims the Mutex class is compatible
with NT4, but my experience seems to be telling me otherwise. Here is
the mutex code I'm using:

public class Form1 : System.Windows.Forms.Form
{

//....(designer code and properties here)
public static bool _bFirstInstance;
public static Mutex _mtxSingleInstance;

//....(other functionality)
[STAThread]
static void Main()
{
//This mutex is used to ensure that only one copy of the
application is running at any time.
_mtxSingleInstance = new Mutex(false,
"Local\\MY_MUTEX_SINGLE_INSTANCE", out _bFirstInstance);
if(_bFirstInstance)
{
// If _bFirstInstance is now true, we're the first instance
of the application;
// otherwise another instance is running and this will not
be called and the applicaiton
// will not start.
Application.Run(new Form1());
}
else
{
string strOutput = "There is already an instance of the
application running.\r\n"
+ "Please check the Icon Tray (right hand side of the
toolbar) for the icon.";
MessageBox.Show(strOutput);
///Else we need to bring up the running instance.
///If we cannot, we need to shut it down and start it
again.
}
}
}

Does anybody have any information on this issue? IS the Mutex class
compatible with NT4 (sp6a)? Is there an issue with my code???

Any help would be great.

Cheers!
Russ
 
W

William Stacey [MVP]

I don't have NT4 anymore to test with. As a workaround and a test, you
could try a native semaphore or a native mutex.

--
William Stacey [MVP]

|I have recently added a mutex to the startup of an application to stop
| users from opening multiple instances. Works great except the
| application no longer works on NT4. The error I get is:
|
| The Application has generated an exception that could not be handled.
|
| Process id = 0x12b (299), Thread id = 0x100 (256)
|
| To test my theory, I created a small windows form app and ran it with
| no problems. I added the same mutex code to it and received the same
| error as noted above.
|
| I double checked in MSDN and it claims the Mutex class is compatible
| with NT4, but my experience seems to be telling me otherwise. Here is
| the mutex code I'm using:
|
| public class Form1 : System.Windows.Forms.Form
| {
|
| //....(designer code and properties here)
| public static bool _bFirstInstance;
| public static Mutex _mtxSingleInstance;
|
| //....(other functionality)
| [STAThread]
| static void Main()
| {
| //This mutex is used to ensure that only one copy of the
| application is running at any time.
| _mtxSingleInstance = new Mutex(false,
| "Local\\MY_MUTEX_SINGLE_INSTANCE", out _bFirstInstance);
| if(_bFirstInstance)
| {
| // If _bFirstInstance is now true, we're the first instance
| of the application;
| // otherwise another instance is running and this will not
| be called and the applicaiton
| // will not start.
| Application.Run(new Form1());
| }
| else
| {
| string strOutput = "There is already an instance of the
| application running.\r\n"
| + "Please check the Icon Tray (right hand side of the
| toolbar) for the icon.";
| MessageBox.Show(strOutput);
| ///Else we need to bring up the running instance.
| ///If we cannot, we need to shut it down and start it
| again.
| }
| }
| }
|
| Does anybody have any information on this issue? IS the Mutex class
| compatible with NT4 (sp6a)? Is there an issue with my code???
|
| Any help would be great.
|
| Cheers!
| Russ
|
 
W

Willy Denoyette [MVP]

The mutex name cannot contain a backslash on NT4, so ,
"Local\\MY_MUTEX_SINGLE_INSTANCE" is illegal.
Note also that NT4 does not know anything about global or local kernel
object namespaces, remove local\\ from your name and all should be fine.

Willy.

|I have recently added a mutex to the startup of an application to stop
| users from opening multiple instances. Works great except the
| application no longer works on NT4. The error I get is:
|
| The Application has generated an exception that could not be handled.
|
| Process id = 0x12b (299), Thread id = 0x100 (256)
|
| To test my theory, I created a small windows form app and ran it with
| no problems. I added the same mutex code to it and received the same
| error as noted above.
|
| I double checked in MSDN and it claims the Mutex class is compatible
| with NT4, but my experience seems to be telling me otherwise. Here is
| the mutex code I'm using:
|
| public class Form1 : System.Windows.Forms.Form
| {
|
| //....(designer code and properties here)
| public static bool _bFirstInstance;
| public static Mutex _mtxSingleInstance;
|
| //....(other functionality)
| [STAThread]
| static void Main()
| {
| //This mutex is used to ensure that only one copy of the
| application is running at any time.
| _mtxSingleInstance = new Mutex(false,
| "Local\\MY_MUTEX_SINGLE_INSTANCE", out _bFirstInstance);
| if(_bFirstInstance)
| {
| // If _bFirstInstance is now true, we're the first instance
| of the application;
| // otherwise another instance is running and this will not
| be called and the applicaiton
| // will not start.
| Application.Run(new Form1());
| }
| else
| {
| string strOutput = "There is already an instance of the
| application running.\r\n"
| + "Please check the Icon Tray (right hand side of the
| toolbar) for the icon.";
| MessageBox.Show(strOutput);
| ///Else we need to bring up the running instance.
| ///If we cannot, we need to shut it down and start it
| again.
| }
| }
| }
|
| Does anybody have any information on this issue? IS the Mutex class
| compatible with NT4 (sp6a)? Is there an issue with my code???
|
| Any help would be great.
|
| Cheers!
| Russ
|
 
D

Dinsdale

Works like a charm, thanks Willy. I would have spent hours going over
that.

Russ
 
W

Willy Denoyette [MVP]

Yep. local is the default.

Willy.

| Will local then be assumed on other platforms (Win2k, XP, 2003?)
|
| Willy Denoyette [MVP] wrote:
| > The mutex name cannot contain a backslash on NT4, so ,
| > "Local\\MY_MUTEX_SINGLE_INSTANCE" is illegal.
| > Note also that NT4 does not know anything about global or local kernel
| > object namespaces, remove local\\ from your name and all should be fine.
| >
| > Willy.
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top