Return to an already open application when a user

2019-01-07 22:35发布

问题:

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:

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



回答2:

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



回答3:

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.