如何检查已在C#

如何检查已在C#

本文介绍了如何检查已在C#.NET运行exe文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是知道,当每次用户启动应用程序,它会检查如果一个实例已在运行的过程。如果它没有运行将启动它,否则将集中到当前的one.i已经尝试了$ C $下单应用程序,但它给很多错误。其运行不正常。 u能为我提供了天波超视距雷达的替代解决方案,这??

What is the procedure to know that when Everytime the user starts the application it will check if an instance is already running. If its not running it will launch it otherwise it will focus to the current one.i have already tried the code for singleton application but its giving lots of errors. its not running properly. can u provide me the othr alternative solution for this??

推荐答案

您应该使用互斥类,喜欢这里解释:Best办法在控制台应用程序C#实现单?

You should use Mutex class, like explained here: Best way to implement singleton in a console application C#?

编辑:我在我的code:

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");
    }
}

这篇关于如何检查已在C#.NET运行exe文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:14