Checking if running by:MadCrazyNewbie
|
Hey Group,
How would I check if my Application is running on a local PC and if it is throw a message to say its already running and quit the the second instance?
Many Thanks MCN
|
| | Reply: by:Cor Ligthert
|
| | Hi MS,
This is the very simple solution from this.
\\Private mut As New Threading.Mutex(True, "myProg", mutCreated) ) Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load If Not mutCreated Then Me.Close() ///
But remember that when you use this, and there can be a complete other program with the same name as yours, that program can also not start.
Better Single instance mostly C# code http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/reaworapps1.asp
I hope this helps?
Cor
|
| | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
|
| |
For example, in your 'Sub Main':
\\Dim m As Mutex = _ New Mutex(False, "{11C92606-65D9-4df2-9AEA-B6A4DA91BCE2}") If m.WaitOne(10, False) Then Application.Run(New Form1()) m.ReleaseMutex() Else MessageBox.Show("Anwendung wird bereits ausgeführt!") End If ///
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
|
| | Reply: by:Cor Ligthert
|
| | Hi MS,
It is almost the same as the solution i did give you however this signature from your program is of course better, (Herfried, can that not direct?, you know that direct and I have to search how.)
However I think that this will give you on a lot of places in the world very much respect
:-))
Cor
|
| | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
|
| | The difference is that it uses 'WaitOne' to avoid possible problems which can occur on some machines (don't know why).
> However I think that this will give you on a lot of places in the world very > much respect >> MessageBox.Show("Anwendung wird bereits ausgeführt!")
Oh, sorry...
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
|
0 Comments:
Post a Comment
<< Home