Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return to an already open application when a user tries to open a new instance

This has been a problem that I haven't been able to figure out for sometime. Preventing the second instance is trivial and has many methods, however, bringing back the already running process isn't. I would like to:

  • Minimized: Undo the minimize and bring the running instance to the front.
  • Behind other windows: Bring the application to the front.

The language I am using this in is VB.NET and C#.

like image 949
MagicKat Avatar asked Sep 18 '08 16:09

MagicKat


4 Answers

If you're using .NET, this seems easier and more straightforward using build-in .NET functionality:

The Weekly Source Code 31- Single Instance WinForms and Microsoft.VisualBasic.dll

like image 36
Tim Erickson Avatar answered Oct 17 '22 19:10

Tim Erickson


I found this code to be useful. It does the detection and optional activation of an existing application:

http://www.codeproject.com/KB/cs/cssingprocess.aspx

like image 192
Big GH Avatar answered Oct 17 '22 19:10

Big GH


These link may be of help:

http://www.ai.uga.edu/mc/SingleInstance.html

It has code to detect another instance running, not sure what you can do with it once you've got the instance though.

like image 2
Mark Ingram Avatar answered Oct 17 '22 19:10

Mark Ingram


In Form_Load this code worked.

 If App.PrevInstance = True Then
     MsgBox "Already running...."
     Unload Me
     Exit Sub
 End If
like image 1
user4565320 Avatar answered Oct 17 '22 17:10

user4565320