Home All Groups Group Topic Archive Search About

Mutex issue on NT4 with 1.1 Framework

Author
1 Jun 2006 11:34 PM
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

Author
2 Jun 2006 2:20 AM
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]

Show quote
"Dinsdale" <russ.ha***@gmail.com> wrote in message
news:1149204877.549357.78020@f6g2000cwb.googlegroups.com...
|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
|
Author
2 Jun 2006 10:26 AM
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.

Show quote
"Dinsdale" <russ.ha***@gmail.com> wrote in message
news:1149204877.549357.78020@f6g2000cwb.googlegroups.com...
|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
|
Author
2 Jun 2006 3:25 PM
Dinsdale
Will local then be assumed on other platforms (Win2k, XP, 2003?)

Willy Denoyette [MVP] wrote:
Show quote
> 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.
Author
2 Jun 2006 4:23 PM
Dinsdale
Works like a charm, thanks Willy. I would have spent hours going over
that.

Russ

Dinsdale wrote:
Show quote
> 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.
Author
2 Jun 2006 5:03 PM
Willy Denoyette [MVP]
Yep. local is the default.

Willy.

Show quote
"Dinsdale" <russ.ha***@gmail.com> wrote in message
news:1149261915.283631.266040@f6g2000cwb.googlegroups.com...
| 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.
|

AddThis Social Bookmark Button