.net紧凑框架:避免程序同时启动两次 [英] .net compact framework: Avoid program being started twice concurrently

查看:104
本文介绍了.net紧凑框架:避免程序同时启动两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何避免用户两次启动同一程序?
当前的实现尝试使用 FindWindow来执行此操作,但是由于该程序需要花费一些时间才能打开第一个窗口,因此用户经常设法两次启动该程序,从而导致错误等。

How can I avoid that a user starts the same program twice? The current implementation tries to do that using "FindWindow", but since it takes some time before the program opens the first window, users regulary manage to start the program twice, causing errors etc.

推荐答案

您必须使用命名的互斥锁,以便可以在各个进程中使用它。出于某种(愚蠢的)原因,CF设计师认为CF开发人员永远不需要这样的东西,因此您有2个选择:

You have to use a named mutex so it can be used across processes. For whatever (stupid) reason, the CF designers figured CF developers would never need such a thing, so you have 2 options:


  1. P /调用CreateMutex和相关的清理内容

  2. 使用已经编写好的实现,例如SDF的来自OpenNETCF的NamedMutex类(为您完成了#1的操作)。

  1. P/Invoke CreateMutex and the associated clean up stuff
  2. Use an already written implementation like the SDF's NamedMutex class (which simply does #1 for you) from OpenNETCF.

实际上也有第三个选项。 SDF的 Application2类有几个<一个href = http://opennetcf.com/library/sdf/html/98173725-375a-b394-89dc-7affb44961cf.htm rel = nofollow noreferrer>运行方法重载,为您包装了此逻辑并强制应用单例行为。

There is actually a 3rd option as well. The SDF's Application2 class has a couple Run method overloads that wraps this logic for you and enforces app singleton behavior.

这篇关于.net紧凑框架:避免程序同时启动两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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