M
Michael A. Covington
See:
http://www.ai.uga.edu/mc/SingleInstance.html
While attempting to use a mutex to allow only one instance of my app to run
at a time (Recipe 4.12 in C# Programmer's Cookbook), I found that if the
mutex is in a local variable in Main(), and my program launches any windows
before Application.Run(), it will lose the mutex upon doing so. It
shouldn't, as far as I can see. Moving the mutex variable outside Main()
and making it static eliminates the problem.
Any ideas? Is there a subtle matter of variable scope and extent that I
haven't understood? Does a process lose its mutexes when it launches a
window? Why?
(The mutex variable still exists, and m.Handle has the same value; but
according to ProcessExplorer, the mutex no longer exists. And all of this
happens only for processes launched from Windows, not under the IDE!)
--
Michael A. Covington - Artificial Intelligence Ctr - University of Georgia
"In the core C# language it is simply not possible to have an uninitialized
variable, a 'dangling' pointer, or an expression that indexes an array
beyond its bounds. Whole categories of bugs that routinely plague C and C++
programs are thus eliminated." - A. Hejlsberg, The C# Programming Language
http://www.ai.uga.edu/mc/SingleInstance.html
While attempting to use a mutex to allow only one instance of my app to run
at a time (Recipe 4.12 in C# Programmer's Cookbook), I found that if the
mutex is in a local variable in Main(), and my program launches any windows
before Application.Run(), it will lose the mutex upon doing so. It
shouldn't, as far as I can see. Moving the mutex variable outside Main()
and making it static eliminates the problem.
Any ideas? Is there a subtle matter of variable scope and extent that I
haven't understood? Does a process lose its mutexes when it launches a
window? Why?
(The mutex variable still exists, and m.Handle has the same value; but
according to ProcessExplorer, the mutex no longer exists. And all of this
happens only for processes launched from Windows, not under the IDE!)
--
Michael A. Covington - Artificial Intelligence Ctr - University of Georgia
"In the core C# language it is simply not possible to have an uninitialized
variable, a 'dangling' pointer, or an expression that indexes an array
beyond its bounds. Whole categories of bugs that routinely plague C and C++
programs are thus eliminated." - A. Hejlsberg, The C# Programming Language