只启动一个应用程序实例控制类
using System;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Zhengzuo.CSharpCode
{
/// <summary>
/// 只启动一个应用程序实例控制类
/// </summary>
public static class SingleInstance
{
private const int WS_SHOWNORMAL = 1;
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
//标志文件名称
private static string runFlagFullname = null;
//声明同步基元
private static Mutex mutex = null;
/// <summary>
/// static Constructor
/// </summary>
static SingleInstance()
{
}
api实现
Mutex实现
设置标志实现
}
}
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Zhengzuo.CSharpCode
{
/// <summary>
/// 只启动一个应用程序实例控制类
/// </summary>
public static class SingleInstance
{
private const int WS_SHOWNORMAL = 1;
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
//标志文件名称
private static string runFlagFullname = null;
//声明同步基元
private static Mutex mutex = null;
/// <summary>
/// static Constructor
/// </summary>
static SingleInstance()
{
}
api实现
Mutex实现
设置标志实现
}
}