using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
namespace WindowsApplication1
{
static class Program
{
/// <summary>
/// 應用程式的主要進入點。
/// </summary>
[STAThread]
static void Main()
{
Process p = checkApp();
if (p == null)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
MessageBox.Show("該程式正在執行","友情提醒",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private static Process checkApp()
{
//獲取當前進程
Process current = Process.GetCurrentProcess();
//通過進程名稱查找進程
Process[] processes = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in processes)
{
if (process.Id != current.Id)
{
//確保例程從EXE文件執行
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\") == current.MainModule.FileName)
{
//返回另一個例程實例
return process;
}
}
}
return null;
}
}
}
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
namespace WindowsApplication1
{
static class Program
{
/// <summary>
/// 應用程式的主要進入點。
/// </summary>
[STAThread]
static void Main()
{
Process p = checkApp();
if (p == null)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
MessageBox.Show("該程式正在執行","友情提醒",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private static Process checkApp()
{
//獲取當前進程
Process current = Process.GetCurrentProcess();
//通過進程名稱查找進程
Process[] processes = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in processes)
{
if (process.Id != current.Id)
{
//確保例程從EXE文件執行
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\") == current.MainModule.FileName)
{
//返回另一個例程實例
return process;
}
}
}
return null;
}
}
}