如何判断一个windows应用程序的实例已经启动? 如何判断一个windows应用程序的实例已经启动?防止用户启动多个该程序的实例!请给出完整代码! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以使用互斥体Mutex类型完成此功能。见如下代码: [STAThread] 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("应用程序已经启动!"); } using System;using System.Collections.Generic;using System.Windows.Forms;using System.Diagnostics;namespace Instance{ static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { foreach (Process p in Process.GetProcesses ()) { if (p.ProcessName == Process.GetCurrentProcess().ProcessName) { return; } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }} 修正一下using System;using System.Collections.Generic;using System.Windows.Forms;using System.Diagnostics;namespace GUI试验{ static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { foreach (Process p in Process.GetProcesses ()) { if (p.ProcessName == Process.GetCurrentProcess().ProcessName && p.Id!=Process.GetCurrentProcess ().Id ) { return; } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }} 最好用mutex判断,用processname判断的话,如果更改了程序名字也可以多次打开的 datagridview取修改后的值问题 C#操作word,怎么删除自定义属性 C#开发的代码的窗口在打开解决方案时不要默认打开! httpwebrequest登录百度空间出错 怎样从object还原成string数组? 请教高手一个关于从配置文件中读取数据库连接字符串的问题? treeview和数据库 谁用过DotRas,来调用plike,请问这样可以连接上SSH么? 就一行代码的程序??? 如何能精通UML和C#? 急救,如何播放一个简单的WAV格式文件? C#如何传直
可以使用互斥体Mutex类型完成此功能。见如下代码:
[STAThread]
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("应用程序已经启动!");
}
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;namespace Instance
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
foreach (Process p in Process.GetProcesses ())
{
if (p.ProcessName == Process.GetCurrentProcess().ProcessName)
{
return;
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;namespace GUI试验
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
foreach (Process p in Process.GetProcesses ())
{
if (p.ProcessName == Process.GetCurrentProcess().ProcessName && p.Id!=Process.GetCurrentProcess ().Id )
{
return;
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}