views:

354

answers:

3

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#.

+1  A: 

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.

Mark Ingram
+3  A: 

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

Big GH
+3  A: 

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

Tim Erickson
+1 - A much cleaner approach that uses the Microsoft.VisualBasic assembly instead of all the Win32 API gunk in the accepted answer. Also allows you to pass command line arguments back to the running instance - a nice bonus.
Tom Bushell