.net compact framework: Avoid program being started twice concurrently

馋奶兔 提交于 2019-12-04 11:14:25

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.

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.

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