On Sunday 21 June 2009 07:39:39 pm Dan Kegel wrote:
I'm more worried about thread shutdown. It seems wrong to just hope that the thread finishes terminating before DllMain returns and the system calls FreeLibrary, but as oldnewthing explains, you can't wait for a thread to terminate inside DllMain.
I don't see a way to it cleanly in DllMain. You could ignore thread shutdown and let the system clean it up at process exit, but then you'd leak threads when an app keeps loading and unloading the dll.
However, it might work if you start the dummy thread right before running the first custom action and take it down after the last one has finished, e.g. in ACTION_FinishCustomActions.
What would the elegant solution be?
Running the custom action in a separate process.
Another blog explains that inheritance of an existing MTA is just a side effect of starting the custom action in a different process, one that happens to have initialized an MTA already.
Sorry, I'm feeling dense. Which other blog, and what's interesting about that?
Sorry, I should have looked it up:
http://blogs.msdn.com/astebner/archive/2005/02/07/368917.aspx
The interesting bit is in the comments.
-Hans