单实例运行tz
(引用了 Microsoft.VisualBasic.ApplicationServices)
SingleInstanceApplicationWrapper.cs
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;
namespace Highflyer
{
/// <summary>
/// 单实例应用程序封装类
/// </summary>
public class SingleInstanceApplicationWrapper : WindowsFormsApplicationBase
{
private readonly Form mainForm;
public SingleInstanceApplicationWrapper(Form form)
{
mainForm = form;
#if DEBUG
this.IsSingleInstance = false;
#endif
#if RELEASE
this.IsSingleInstance = true;
#endif
}
protected override bool OnStartup(StartupEventArgs e)
{
Application.Run(mainForm);
return false;
}
protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e)
{
// 这里可以把本次使用的参数传给之前的实例,本人在一个WPF 屏幕键盘项目里传送了键盘显示方式(数字、英文、手写)参数
//e.BringToForeground = true;
//if (e.CommandLine.Count > 0)
//{
// app.DealArgs(e.CommandLine.ToArray());
//}
}
}
}
Program.cs
using System;
using System.Windows.Forms;
using Highflyer;
namespace Eparcar.ParkLocal.GateBoxClient
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MainForm mainForm = new MainForm();
SingleInstanceApplicationWrapper wrapper = new SingleInstanceApplicationWrapper(mainForm);
wrapper.Run(args);
}
}
}
单实例运行tz的更多相关文章
- Qt实现应用程序单实例运行--LocalServer方式
使Qt应用程序能够单实例运行的典型实现方法是使用共享内存实现.该方法实现简单,代码简洁. 但有一个致命缺陷:共享内存(QSharedMemory)实现的单程序运行,当运行环境是UNIX时,并且程序不幸 ...
- Winform 单实例运行
Winform 单实例运行 前言 前两天在博客园看到<如何防止程序多次运行>,文章写的很好,最后还留下一个问题给我们思考.关于Winform的防止多次运行,曾经也想研究过,但是后来工作上没 ...
- C++实现程序单实例运行的两种方式
简介 在我们编写程序的时候,经常会注意到的一个问题就是如何能够让程序只运行一个实例,确保不会让同一个程序多次运行,从而产生诸多相同进程,给我们的带来不便呢?那么常用的有以下四种方法,第一种方法是通过扫 ...
- Windows进程单实例运行
场景 Windows进程单实例运行,如果有进程没有退出,继续等待,直到进程完全退出,才会进入下一个实例 HANDLE pHandle = NULL; do { pHandle = ...
- c#设计应用程序单实例运行
利用WindowsFormsApplicationBase的IsSingleInstance来控制应用程序只能单实例运行. [DllImport("user32.dll", Ent ...
- c# 单实例运行
/// <summary> /// 单实例运行程序 /// </summary> static void SingleInstanceRun() { bool isAppRun ...
- C#实现单实例运行
C#实现单实例运行的方法,也有多种,比如利用 Process 查找进程的方式,利用 API findwindow 查找窗体的方式,还有就是 利用 Mutex 原子操作,上面几种方法中, 综合考虑利用 ...
- WinForm 登录窗体 + 单实例运行
关于怎么在winform里增加登录窗体或者如何让winform程序单实例运行网上都很多例子. 然而两者结合起来呢? //Program.cs static class Program { public ...
- DevExpress Winform使用单例运行程序方法和非DevExpress使用Mutex实现程序单实例运行且运行则激活窗体的方法
原文:DevExpress Winform使用单例运行程序方法和非DevExpress使用Mutex实现程序单实例运行且运行则激活窗体的方法 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA ...
随机推荐
- Spring MVC控制层的返回类型--String类型与Bean类型
SpringMVC控制层的返回类型形式多样,现拿其中的两种--String类型与Bean类型作以说明. 一.测试项目的结构 说明:(jsp的名字没起好) 控制层:UserController.java ...
- Web网站架构设计
目录 [隐藏/显示] 1 - Web负载均衡 1.1 - 使用商业硬件实现 1.2 - 使用开源软件 1.3 - 使用windows自带的互载均衡软件 1.4 - 总结2 - 静态网站 ...
- 《Publish or Perish》——从某种角度来说,我们也算和世界同步了呢。
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemB:Light Bulb
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 题意:求影子的最长长度L; 当灯,人头和墙角成一条直线时(假设此时人 ...
- Binding to the Most Recent Visual Studio Libraries--说的很详细,很清楚
Every version of Visual Studio comes with certain versions of the Microsoft libraries, such as the C ...
- hadoop No FileSystem for scheme: hdfs
http://stackoverflow.com/questions/17265002/hadoop-no-filesystem-for-scheme-file This is a typical c ...
- ASP.NET 4.5.256 has not been registered on the Web server
请见:http://answers.microsoft.com/en-us/insider/forum/insider_apps-insider_other/aspnet-45256-has-not- ...
- N-Queens leetcode java
题目: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two que ...
- 苹果p12文件--一个苹果证书怎么多次使用(蛋疼,这些问题只有和其他企业合作才会遇到,别人的账号不可能给你,蛋疼....)
在苹果开发者网站申请的证书,是授权mac设备的开发或者发布的证书,这意味着一个设备对应一个证书,但是99美元账号只允许生成3个发布证书,两个开发证书,这满足不了多mac设备的使用,使用p12文件可以解 ...
- HeadFirst设计模式之模板方法模式
一. 1.The Template Method defines the steps of an algorithm and allows subclasses to provide the impl ...