最近看了一个老外的写的方法,通过进程间通信保证只启动一个程序:
客户端主窗体继承该接口,
SingleInstancing
注意,由于该方法可能是在另一个进程中调用所以在其中调用主窗体时需要回到主窗体
Form1
namespace WindowsApplication1
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

Windows 窗体设计器生成的代码

private System.Windows.Forms.Label label1;
}
}


启动程序如下:
Code
具体代码:
Winform单一实例















浙公网安备 33010602011771号