读书人

c#兑现同一个实例只能运行一次

发布时间: 2012-10-16 09:57:37 作者: rapoo

c#实现同一个实例只能运行一次
using System;
using System.Collections.Generic;
using System.Text;
using IRADManager.Common;
using System.Diagnostics;
using Microsoft.Win32;
using System.IO;
using System.Resources;
using System.Reflection;
using System.Threading;
using System.Globalization;

namespace common
{
public class util
{
///
///方法RunedTest表示:根据当前进程名判断是否存在相同进程,如果存在只能运行一个实例并且返回true,否则返回false.
///
public static bool RunedTest()
{
Process cp = Process.GetCurrentProcess();
Process[] ps = Process.GetProcessesByName(cp.ProcessName);
return ps != null && ps.Length >1;

}
}
}

读书人网 >C#

热点推荐