Checking if running

  • Thread starter Thread starter MadCrazyNewbie
  • Start date Start date
M

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
 
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
 
* "MadCrazyNewbie said:
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?

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
///
 
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.)
New Mutex(False, "{11C92606-65D9-4df2-9AEA-B6A4DA91BCE2}")

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!")

:-))

Cor
 
* "Cor Ligthert said:
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.)

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

Oh, sorry...
 
Back
Top