.net compact framework: Avoid program being started twice concurrently

纵然是瞬间 提交于 2019-12-06 05:37:24

问题


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.


回答1:


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/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.

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.




回答2:


Use this: http://msdn.microsoft.com/en-us/netframework/bb943002.aspx

Many of the alternatives out there are either too complicated or don't work all of the time.



来源:https://stackoverflow.com/questions/867050/net-compact-framework-avoid-program-being-started-twice-concurrently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!