Have you tried my code above?
--
William Stacey [C# MVP]
PowerLocker, PowerPad
www.powerlocker.com
| |
| > Make sure your Mutex doesn't get collected before this program instance
| > terminates, one way to achieve this is by applying the using idiom like
| > this:.
| >
| > ...
| > bool firstInstance;
| > using (Mutex AppMutex = new Mutex(true, new
| > Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").ToString(), out
| > firstInstance))
| > {
| > if (firstInstance== true)
| > {
| > // run your program code from here
| > }
| > } // end using scope, mutex released here.
| > ...
| >
| > where: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is just some valid uuid, but
| > of course you are free to use anything else to uniquely identify the
| > program.
| >
| > Willy.
|
| Now this is very weird!
|
| I tried your above code, and it worked perfectly on 64-bit Vista but not
on
| 32-bit XP.
|
| However, the version of XP I was testing it on was running in a Virtual PC
| 2007 virtual machine, so I wondered if that might be the cause, though i
| couldn't imagine why...
|
| Therefore, I tried it on XP running on a "real" machine, and it worked
| perfectly!
|
| Obviously, I'm happy that it works but I'm not particularly impressed... I
| use VPC 2007 all the time for testing my apps, so I wonder what else might
| behave differently in this scenario...?
|
| Unfortunately, I don't know enough about mutexes and how they're
generated,
| but do you have any idea why a virtual machine might cause a mutex to
behave
| differently from a real machine...?
|
| I'm about to try it on Vista running in a virtual machine, and will let
you
| know what happens...
|
| I'll also post in the VPC newsgroup to see if anyone has come across this
| before...
|
|
| --
|
http://www.markrae.net
|