讓程序只運行一個實例
在這裡
方法一
代碼如下
using System;
using System
using System
using System
using System
using System
using System
using System
namespace MyWork_
{
class Program
{
static void Main(string[] args)
{
Process[] processes = Process
Process currentProcess = Process
ProcessModule currentPM = currentProcess
int same =
ArrayList proList = new ArrayList(); //將相同實例加入此集合中
foreach (Process p in processes)
{
try//由於進程不同
{
if (p
if (p
{
System
if (pm
{
same++;
proList
}
if (same >
{
same++;
proList
if (same >
{
for (int i =
if (((Process)(proList[i]))
{
Console
Thread
((Process)(proList[i]))
}
}
}
}
}
}
catch
{ }
}
Console
}
}
}
方法二
代碼如下
?using System;
using System
using System
using System
using System
using System
using System
using System
[assembly: Help(
public class HelpAttribute : Attribute
{
public HelpAttribute(String Description_in)
{
this
}
protected String description;
public String Description
{
get
{
return this
}
}
}
class Program
{
static void Main(string[] args)
{
HelpAttribute HelpAttr
HelpAttribute HelpAttr
Process currentProcess = Process
Assembly a = Assembly
foreach (Attribute attr in a
{
HelpAttr
if (null != HelpAttr
{
//Console
break;
}
}
Process[] processes = Process
int same =
ArrayList proList = new ArrayList(); //將相同實例加入此集合中
foreach (Process pro in processes)
{
try//由於進程不同
{
if (pro
if (pro
{
Assembly b = Assembly
foreach (Attribute attr in b
{
HelpAttr
if (null != HelpAttr
{
if (HelpAttr
{
same++;
proList
if (same >
{
for (int i =
{
if (((Process)(proList[i]))
{
Console
Thread
((Process)(proList[i]))
}
}
}
}
}
}
}
}
catch
{
}
}
Console
}
From:http://tw.wingwit.com/Article/program/ASP/201311/21798.html