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

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

问题描述

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

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

过去,我使用库代码来控制一直看起来很复杂的互斥锁.当我在 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天全站免登陆