方法一:遍历正在有相同名字运行的例程 using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Runtime.InteropServices; namespace DHPSS.COM { /// <summary> /// c#程序只运行一次,C#例程只运行一次 /// http://blog.csdn.net/nnsword /// QQ:16349023 /// </summary> public class CHandleRunningPro { /// <summary> /// const int, ShowWindowAsync 使用时的参数,让窗体正常显示确保没有隐藏和最小化。 /// </summary> private const int WS_SHOWNORMAL = 1; /// <summary> /// 功能:遍历所有运行的例程,判断是否已经有相同名字的例程。 /// 实现:遍历所有运行的例程,如果有与自己名字相同的比较 ID 是否相同。 /// 如果ID不同说明已经有实例在运行,则把该实例返回。 /// 如果没有则返回 null /// </summary> /// <returns>有相同名