如何防止多次启动我的应用程序? [英] How can I prevent launching my app multiple times?
本文介绍了如何防止多次启动我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我点击开始菜单中的应用程序快捷方式,一个新的实例启动。我需要避免这个。
如何防止多次启动?
解决方案
在程序启动时检查同一进程是否已经运行:
使用System.Diagnostics;
static void Main(string [] args)
{
String thisprocessname = Process.GetCurrentProcess()。
if(Process.GetProcesses()。Count(p => p.ProcessName == thisprocessname)> 1)
return;
}
I deployed my C# WinForms application using ClickOnce installation. Everything works fine with it (after a lot of work) :), but now I'm facing a problem:
Whenever I click on the application shortcut in the Start menu, a new instance starts. I need to avoid this.
What can I do to prevent multiple launches?
解决方案
At program startup check if same process is already running:
using System.Diagnostics;
static void Main(string[] args)
{
String thisprocessname = Process.GetCurrentProcess().ProcessName;
if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1)
return;
}
这篇关于如何防止多次启动我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文