如何确保仅运行我的应用程序的一个实例? [英] How to ensure only a single instance of my application runs?

查看:81
本文介绍了如何确保仅运行我的应用程序的一个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi XE VCL是否支持确保仅运行一个应用程序实例?

Is there support in the Delphi XE VCL for ensuring only a single instance of an application is running?

过去,我使用库代码来控制一个看起来总是很复杂的Mutex。当我在Delphi XE中启动一个新项目时,我想知道是否需要挖掘旧代码,或者XE中已经内置了支持?还是有另一个易于应用的美观又现代的代码?

In the past, I've used library code to control a Mutex which has always seemed complicated. As I'm starting a new project in Delphi XE, I wonder if I need to dig up that old code, or if there is support built into XE already? Or is there another easy to apply code that is nice and modern?

推荐答案

我使用JCL来做到这一点:

I use JCL to do this:

program MyProgram;

uses
  JclAppInst;

begin
  JclAppInstances.CheckSingleInstance; // Added instance checking
  Application.Initialize;
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.

有关此文档以及通知方案的信息,请参见 JCL Wiki

Documentation for this, and the notification scheme, is at the JCL Wiki.

这篇关于如何确保仅运行我的应用程序的一个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆