当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 利用C#线程机制实现应用程序的单实例运行

ASP.NET
Web服务器控件:LinkButton控件
Web服务器控件:ListBox控件
Web服务器控件:ListItem控件
Web服务器控件:Literal控件
Web服务器控件:Panel控件
Web服务器控件:PlaceHolder控件
Web服务器控件:RadioButton控件
Web服务器控件:RadioButtonList控件
Web服务器控件:BulletedList控件
Web服务器控件:Style控件
Web服务器控件:Table控件
Web服务器控件:TableCell控件
Web服务器控件:TableRow控件
Web服务器控件:TextBox控件
Web服务器控件:XML控件
Validation服务器控件:CompareValidator控件
Validation服务器控件:CustomValidator控件
Validation服务器控件:RangeValidator控件
Validation服务器控件:RegularExpressionValidator控件
Validation服务器控件:RequiredFieldValidator控件

ASP.NET 中的 利用C#线程机制实现应用程序的单实例运行


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 82 ::
收藏到网摘: n/a


只要你的程序中Main入口是如下的,则你的程序在运行时,在一个时刻只能有一个程序实例,比如Winamp就是这种,当它在运行时,再又击这个程序,是不会再运行一个实例的.
代码很简单
[STAThread]

static void Main(string[] args)

{

bool isExist; System.Threading.Mutex mutex=new System.Threading.Mutex(true,"myApp",out isExist); //这里的myApp是程序的标识,建议换成你的程序的物理路径,这样的话如果在一个操作系统中这个标志不会和其它程序冲突 if(isExist)Environment.Exit(1);//实例已经存在,退出程序}