I wrote a traffic monitoring software that I want the computer to run only once, and the code is as follows:
Find, immediately, click on the software, it will prompt "An instance has been run", but,After waiting for 30 seconds, then click on the software, and it runs successfully againOnce !!
It's a pity.The above code is fine in DEBUG mode, but it doesn't work in RELEASE. The problem is that Mutex is declared as a local variable, and in relese mode due to optimization issues, possibly because the compiler thinks Mutex is no longer used
used, recycled, tested by myself,
Put Mutex on top and set it as a static variable to !!!RightThe code is as follows:
|