Completely solve the problem that NetEase duilib process sometimes cannot exit

background

In use Duilib Netease open source Windows application development time, along with increasingly more functionality, you may experience problems not completely withdraw from the process.

The reasons may be:

  • Related resources are not properly released
  • BUG
  • The background thread did not exit
  • ……

At this time, we might as well refer to some Android practices, at some entrances, call the system API to force the end of the entire process.

Kill My Self

In NetEase's duilib framework, when the entire application exits, the Cleanup function will be called back. At this time, we only need to end the current process in this function:

// kill myself
HANDLE hself = GetCurrentProcess();
TerminateProcess(hself, 0);

The complete code is as follows:

void MainThread::Cleanup() {
    
    
    // sdk dispose
    cim::cleanup();

    ui::GlobalManager::Shutdown();
    SetThreadWasQuitProperly(true);
    nbase::ThreadManager::UnregisterThread();
    
    HANDLE hself = GetCurrentProcess();
    TerminateProcess(hself, 0);
}

Guess you like

Origin blog.csdn.net/xmcy001122/article/details/113558735