Saturday, March 20, 2010
Wedding Cake, Mounting Designs
Let's see if and what control you are running a single instance of a particular application with Visual Studio 2005. In particular with VB.NET 2005.
We have 3 paths to follow (I will not put all the code here but the links where the full sample).
1 .- Check how many processes are running our application based on the process name. If
Process.GetProcessesByName (Process.GetCurrentProcess.ProcessName). Length >
1 Then MessageBox.Show ("There is already an instance of the application")
Application.Exit () End If
With Process.GetProcessesByName bring the processes running under the name Process.GetCurrentProcess.ProcessName (that of our fair application), if you bring more than one is because another run and then we (Application.Exit ()).
can see examples on the following links:
http://www.freevbcode.com/ShowCode.Asp?ID=5333
http://www.elguille.info/colabora/puntonET/anibal_appPrevinstance.htm
The disadvantage of this procedure is that if you rename the executable can run simultaneous instances (Each executable name will have a different process name.)
2 .- Using Mutex
is trying to gain access to a named Mutex (the IDEA is that is unique to our application), if not achieved is because someone took it before, that is .. there is already an instance of nmuestra application.
http://www.freevbcode.com/ShowCode.Asp?ID=5845
3 .- Simple but effective:
In the Visual Studio double-click My Project -> Application tab -> check in the "Make Single Instance Application"
http://www.canalvisualbasic.net/foro/visual-basic-net/instancia-unica-de-aplicacion-12358/
I'll stick with the 3. As a friend would say: "Rustic but effective:)
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment