.net compact: avoid running the program twice at the same time

How can I avoid the user running the same program twice? The current implementation is trying to do this using "FindWindow", but since it takes some time to open the first program window, users can run the program twice, causing errors, etc.

+4
source share
2 answers

You must use a named mutex so that it can be used in all processes. For some (stupid) reason, CF designers thought that CF developers would never need such a thing, so you have 2 options:

  • P / Invoke CreateMutex and its associated cleanup element
  • Use an already written implementation, such as the SDF class NamedMutex (which is just # 1 for you) from OpenNETCF.

In fact, there is a third option. SDF The Application2 class has a pair of Overloading the startup method that wraps this logic for you and enables the application of single-user behavior.

+4
source

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

Many of the alternatives there are either too complex or do not work all the time.

+2
source

Source: https://habr.com/ru/post/898790/


All Articles