只运行一个程序实例 程序没有运行则运行,若已经运行则不用做任何事了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 static void Main() { if (!isRunning("Gserver"))//不存在才运行. { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Gserver()); } } //根据进程名称判断是否有同名进程正在运行中 private static bool isRunning(string processName) { return (System.Diagnostics.Process.GetProcessesByName(processName).Length > 1) ? true : false; } 控制进程只运行一个实例代码请参考这个网址 http://www.cnblogs.com/gengchengxiang/articles/991666.html 单件模式或者使用多线程的互斥体技术这个是互斥体技术Boolean createdNew; //返回是否赋予了使用线程的互斥体初始所属权 System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew); //同步基元变量 if (createdNew) //赋予了线程初始所属权,也就是首次使用互斥体 { Application.Run(new Form1()); /s/这句是系统自动写的 instance.ReleaseMutex(); } else { MessageBox.Show("已经启动了一个程序,请先退出!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Error); Application.Exit(); } 单件模式你可以看看这篇文章http://terrylee.cnblogs.com/archive/2005/12/09/293509.html static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (runone()) Application.Run(new Form2 ()); } private static System.Threading.Mutex mutex; private static bool runone() { bool one; mutex = new System.Threading.Mutex(true, "WindowsApplication2", out one); return one; } }我记得前几天有人刚问过这个问题...在Program.cs理. 强类型的DataSet更新主从表的事物应该怎么写呢? [winform]按钮最大化后怎么始终在最下方 C# 文本框选择后,再选择下拉框选择不消失 求一个正则表达式 谁知道vs.net2005的菜单合并是哪个属性 Winform中DataSet得到数据表以后绑定到DataGrid上,怎样在窗体中修改DataGrid值的时候同时修改DataSet中的内容然后更新到数据库 继承类能同时继承该类的接口么 多线程锁定方法求助 关于DataGird列显示为(空)的问题!!! 怎么回事 网页采集高手come in mobile 数据库 大数据量 如何实现分页查询?
{
if (!isRunning("Gserver"))//不存在才运行.
{ Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Gserver());
}
} //根据进程名称判断是否有同名进程正在运行中
private static bool isRunning(string processName)
{
return (System.Diagnostics.Process.GetProcessesByName(processName).Length > 1) ? true : false;
}
http://www.cnblogs.com/gengchengxiang/articles/991666.html
这个是互斥体技术
Boolean createdNew; //返回是否赋予了使用线程的互斥体初始所属权
System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew); //同步基元变量
if (createdNew) //赋予了线程初始所属权,也就是首次使用互斥体
{
Application.Run(new Form1()); /s/这句是系统自动写的
instance.ReleaseMutex();
}
else
{
MessageBox.Show("已经启动了一个程序,请先退出!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
Application.Exit();
}
http://terrylee.cnblogs.com/archive/2005/12/09/293509.html
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (runone())
Application.Run(new Form2
());
}
private static System.Threading.Mutex mutex;
private static bool runone()
{
bool one;
mutex = new System.Threading.Mutex(true, "WindowsApplication2", out one);
return one;
}
}我记得前几天有人刚问过这个问题...在Program.cs理.