.net - 如何检查已经在 c#.net 中运行的 exe?

标签 .net exe

什么程序知道当每次用户启动应用程序时,它都会检查一个实例是否已经在运行。如果它没有运行,它将启动它,否则它将专注于当前的。我已经尝试了单例应用程序的代码,但它给出了很多错误。它运行不正常。你能为我提供其他替代解决方案吗??

最佳答案

你应该使用 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/

相关文章:

c# - 将内存中的位图图像转换为 4 维数组,如 numpy

c# - ConfigurationManager.GetSection(sectionName) 在执行单元测试时返回 null

python - 我正在使用 PyInstaller 将 .py 文件转换为 .exe 文件,但我遇到了困难?

ubuntu 12.04下使用cx-freeze将Python脚本写入Windows exe文件

php - IE9 中的 "This type of file could harm your computer"消息

.net - native 应用程序内的 C# .NET 用户控件。资源链问题

c# - 使用 Bitmiracle Libtiff.net 创建 Bigtiff (>4GB) 文件

c++ - 如何在 C++ 中使 .Exe 复制自身?

c# - 在 .NET 中捕获存储过程打印输出

python - Windows 10/11 上的 .exe 文件附带的文件存储在哪里?