什么程序知道当每次用户启动应用程序时,它都会检查一个实例是否已经在运行。如果它没有运行,它将启动它,否则它将专注于当前的。我已经尝试了单例应用程序的代码,但它给出了很多错误。它运行不正常。你能为我提供其他替代解决方案吗??
最佳答案
你应该使用 Mutex
类,就像这里解释的那样:Best way to implement singleton in a console application C#?
编辑:我的代码中有这个:
class Program
{
public const string AppName = "...";
private static readonly Mutex mutex = new Mutex(true, Program.AppName);
public Program()
{
if (!mutex.WaitOne(TimeSpan.Zero, true))
throw new ApplicationException("Another instance already running");
}
}
关于.net - 如何检查已经在 c#.net 中运行的 exe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2182385/