public static void Main(string[] args)
{
//声明互斥体。
Mutex mutex = new Mutex(false, "ThisShouldOnlyRunOnce");
//判断互斥体是否使用中。
bool Running = !mutex.WaitOne(0, false);
if (! Running)
Application.Run(new FormLogin());
else
MessageBox.Show("应用程序已经启动!");
}
{
//声明互斥体。
Mutex mutex = new Mutex(false, "ThisShouldOnlyRunOnce");
//判断互斥体是否使用中。
bool Running = !mutex.WaitOne(0, false);
if (! Running)
Application.Run(new FormLogin());
else
MessageBox.Show("应用程序已经启动!");
}
解决方案 »
- 销售趋势分析图
- Form_load里给ListBox控件绑数据,也引发ListBox_SelectedIndexChanged事件?
- 关于VS.net2005的CrystalReport直接打印问题(winform)
- C#的wmi问题
- C# 静态类成员的问题
- 如何实现像QQ一样的远程登录
- 在用SOCKET发送数据的时候,接收方如何区分数据的类型呢?愚翁老大,这次又要麻烦你了!!!
- 关于catch中再throw的问题
- 上传文件的问题->c/s上传一个文件夹?(up有分)
- 怎么把一个实体类序列化XML,然后向XML添加数据
- 为答谢 alias88 的无私帮助,再此赠分,表示感谢。
- 请问怎样在C#中清空ACCESS的数据表??
bool createdNew;
Mutex m = new Mutex(true, "yourname", out createdNew);
if (! createdNew)
{
MessageBox.Show("Only one name is allowed at a time.");
return;
}
Application.Run(new Start());
GC.KeepAlive(m);
{
//log
Log("Process starting");
//current process
Process current = Process.GetCurrentProcess();
//processes name
Process[] processes = Process.GetProcessesByName (current.ProcessName);
foreach (Process process in processes)
{
//id compare
if (process.Id != current.Id)
{
//path compare
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
{
//log
Log("Process has benn staring");
//Return the other process instance.
return process;
}
}
}
Log("Process start");
//No other instance was found, return null.
return null;
}
static void Main()
{
Log("Main");
//getinstance
if(FileWatch.RunningInstance() == null)
{
Application.Run(new FileWatch());
}
//show message
else
{
//log
Log("Application has stoped"); MessageBox.Show("error","警告",
MessageBoxButtons.OK,MessageBoxIcon.Stop);
}