To prevent users from exiting the system abnormally, set E. Cancel = true in the formclosing event of the form.
However, the result is that if a user wants to quit, the user cannot quit. The solution is to use a variable that can exit for analysis. For example, we can set iscanexitProgramSet iscanexit to true when you can exit, which is troublesome.
In addition, this situation also occurs when multithreading is used. At that time, neither application. Exit nor apllication. exitthread can be used to completely exit the system. Although the program interface has exited, the process is still running in the task manager.
This indicates that application. Exit or apllication. exitthread cannot be used to completely exit.
Later, we found that in addition to the preceding two exit methods, there is also an environment. Exit method, which can be called to completely exit the system.
At this time, it is not difficult to find that even if our program cannot exit normally, but when debugging, click the stop button in vs2005 and it will end, in the task manager, we cannot see the environment. the exit method should have the same effect as the stop button in vs2005.