I know I can add a shutdown hook which will run in a new Thread, but how can I add a shutdown hook for the current thread, if even possible? I need some code to be run in the same thread as which created the shutdown hook but I couln't find an answer yet.
edit: some background information:
I'm writing a library which calls CoInitialize from MS COM interface whenever a specific object is created. I want the user to not need to care about uninitializing COM thus I thought I could simply call CoUninitialize in a shutdown hook. But the uninitialization must happen from the same thread as from which it was initialized, so it doesn't work with a shutdown hook.