Hi,

I've got the following C# code that works perfectly to prevent a 2nd
instance of my C# app:

bool bAppNotRunning = false;
Mutex MutApp = new Mutex(true, "MyC#AppMutex", out bAppNotRunning)
if(bAppNotRunning == true)
{
Run the app and do work...
MutApp.ReleaseMutex();
}


I did the same thing in another app that's in VB. NET to prevent a 2nd
instace of it:

Dim bAppNotRunning As Boolean

bAppNotRunning = False
MutApp = New Mutex(True, "MyVBAppMutex", bAppNotRunning)
If(bApNotRunning = True) Then
Run the app and do work...
MutApp.ReleaseMutex()
End If


Why doesn't the VB version work? bAppNotRunning comes back True from the
Mutex constructor even when another instance of the app is already running?!

What gives? Any ideas would be appreciated.

TIA,

--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> john.bowman@thermo.com

Re: Mutex Differences VB.NET & C# by Frank

Frank
Fri May 21 15:23:55 CDT 2004


> I've got the following C# code that works perfectly to prevent a 2nd
> instance of my C# app:
>
> bool bAppNotRunning = false;
> Mutex MutApp = new Mutex(true, "MyC#AppMutex", out bAppNotRunning)
> if(bAppNotRunning == true)
> {
> Run the app and do work...
> MutApp.ReleaseMutex();
> }

if ( bAppNotRunning ) ... forget about the " == true", because bAppRunning
is already a boolean value.

That's also the problem with the VB.NET-code:

>
> Dim bAppNotRunning As Boolean
>
> bAppNotRunning = False
> MutApp = New Mutex(True, "MyVBAppMutex", bAppNotRunning)

-> in the next line, true is probably asssigned to bAppRunning because of
the braces and because "=" is in VB.NET used for both, assigning and
comparing.

> If(bApNotRunning = True) Then


So ... if you check a boolean value, do it like this:

If (bAppNotRunning) Then ...

:-)

Regards,

Frank Eller



Re: Mutex Differences VB.NET & C# by John

John
Fri May 21 15:31:02 CDT 2004

Frank,

Thanks for the help.. that seems to do it.

John

"Frank Eller [MVP]" <feNOSPAM@frankeller.de> wrote in message
news:eJ9ULG3PEHA.632@TK2MSFTNGP12.phx.gbl...
>
> > I've got the following C# code that works perfectly to prevent a 2nd
> > instance of my C# app:
> >
> > bool bAppNotRunning = false;
> > Mutex MutApp = new Mutex(true, "MyC#AppMutex", out bAppNotRunning)
> > if(bAppNotRunning == true)
> > {
> > Run the app and do work...
> > MutApp.ReleaseMutex();
> > }
>
> if ( bAppNotRunning ) ... forget about the " == true", because bAppRunning
> is already a boolean value.
>
> That's also the problem with the VB.NET-code:
>
> >
> > Dim bAppNotRunning As Boolean
> >
> > bAppNotRunning = False
> > MutApp = New Mutex(True, "MyVBAppMutex", bAppNotRunning)
>
> -> in the next line, true is probably asssigned to bAppRunning because of
> the braces and because "=" is in VB.NET used for both, assigning and
> comparing.
>
> > If(bApNotRunning = True) Then
>
>
> So ... if you check a boolean value, do it like this:
>
> If (bAppNotRunning) Then ...
>
> :-)
>
> Regards,
>
> Frank Eller
>
>



Re: Mutex Differences VB.NET & C# by Frank

Frank
Sat May 22 16:05:08 CDT 2004

> Frank,
>
> Thanks for the help.. that seems to do it.

You're welcome :-)

Regards,

Frank Eller
www.frankeller.de