Application is still running in memory after Application.Exit() is called

后端 未结 4 1324
不思量自难忘°
不思量自难忘° 2020-12-31 12:19

The application I am building is still running in memory (checked in Task Manager) after it is closed using Application.Exit(). Because of this when I am runnin

4条回答
  •  Happy的楠姐
    2020-12-31 12:21

    Because of using Foreground Thread and Lybda Expession thread So, threads which will continue to run until the last foreground thread is terminated. In another way, the application is closed when all the foreground threads are stopped. that's why the application won't wait until the background threads are completed, but it will wait until all the foreground threads are terminated. So In that case we have to explicitly stop the all running threads by using

    Environment.Exit(Environment.ExitCode);

    This kept the memory managed perfectly, with no memory leak.

提交回复
热议问题