windows 当用户尝试打开新实例时返回到已打开的应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/94274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:14:16  来源:igfitidea点击:

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

c#.netwindowsvb.net

提问by MagicKat

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

我使用的语言是 VB.NET 和 C#。

采纳答案by Big GH

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

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

回答by Tim Erickson

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

如果您使用的是 .NET,那么使用内置的 .NET 功能似乎更容易、更直接:

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

每周源代码 31- 单实例 WinForms 和 Microsoft.VisualBasic.dll

回答by Mark Ingram

These link may be of help:

这些链接可能会有所帮助:

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

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.

它具有检测另一个正在运行的实例的代码,但不确定一旦获得该实例您可以用它做什么。