On a WPF application I have (too easy to complicate it with any MVVM monstrosity) I start another thread when the main form, is created. The thread is NOT a background thread. I need to be sure that some unmanaged resources I open are correctly cleaned up when the thread closes.
The thread is created and it works under the whole application's life. Now I close the main window (I have ShutdownMode="OnMainWindowClose"). On my Closed event I signalize the thread to terminate and wait for it (Join). When debugging and setting a break point on the Closed logic, it works fine. The thread terminates and the application closes gratefully.
Running the program however it seems like the code in Closed sometimes doesn't get executed? The application closes but I see a zombie process in the TaskManager like if the second thread is still running.
Any ideas?