Check if instance of program is already running

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

oHi,

I want to check for a Windows form program if an instance of the prgram is
already running: if yes the program's window should be activated and no
second program instance should be started.

How can I perform this task in VB.Net?

Thanks in advance.
 
Henry said:
I want to check for a Windows form program if an instance of the prgram is
already running: if yes the program's window should be activated and no
second program instance should be started.

Detecting another instance of the application:

<URL:http://www.yoda.arachsys.com/csharp/faq/#one.application.instance>

Bringing a window into the foreground (requires the window's handle, which
can be obtained by getting the process' 'Process' object and getting its
'MainWindowHandle' property value):

<URL:http://groups.google.de/groups?selm=#[email protected]>
 
Henry,

When you are sure that your program name is a real unique name than this one
is very simple.
\\\
Private mut As New Threading.Mutex(True, "myProgram", mutCreated)
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not mutCreated Then Me.Close()
'etc
End Sub
//
I hope this helps?

Cor
 
Thanks Cor and Herfried!

That is exactly what I needed and it works quite fine.

Best regards

Henry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top