WPF学习笔记 - 如何用WPF创建单实例应用程序

来源:互联网 发布:老域名 编辑:程序博客网 时间:2024/06/07 09:44

使用一个已命名的(操作系统范围的)互斥量。

bool mutexIsNew;

using(System.Threading.Mutex m = new System.Threading.Mulex(true, uniqueName, out mutexIsNew))

{

    if(mutexIsNew)

    {

        //This is the first instance, can run the appliacation

    }

    else

    {

        //There is an instance running, exit.
    }

}

因为是操作系统范围的,所以需要确定参数uniqueName指定的名字不会被其他应用程序使用。

原创粉丝点击