com - Hooking thread exit -


Is there a way to hook the exit of managed threads (i.e. run some code on any thread,?) < / P>

I have developed the mechanism to extract the thread which works for the some thread Step 1: Develop a 'hook' STA com class which takes a callback function And it says in its destructor Step 2: Make a thread-static example of this object on the thread I want to hook, and convert the object to a unmanaged function pointer to a managed representative. The delegation then becomes a call on the exit of the thread (Since the CLR call IUnknown :: Release all STA Com RCW as part of the thread exhaust).

This mechanism works, for example the code using the thread class.

However, this does not seem to work for the main thread of the application (this is a console or window app) The 'hook' com object seems to have been removed very late in the shutdown process and the attempt to call the representative fails.

(I want to implement this feature so I can run some native com code, working on thread working with SATA com objects, which was created on the thread, before 'too late It is no longer possible to work with STA Com Objects (that is, it is no longer possible to get it done before thread is out).

Do you control the thread construction? It's possibly easier to wrap the code of the thread in a try ... end in the section, and finally put your code into it.

Note that when AppDomain stops, you can never make sure that your code is ever called "Dististor" when you call it C ++ / CLI Destistor - I.e. immersion method () method?

If you have to support hooking before exiting the process, you AppDomain.CurrentDomain.ProcessExit event - which is an unrestricted exception, or AppDomain.CurrentDomain. UnhandledException can not try to fire which only start to fire on an unrestricted exception.

None of these looks particularly strong, note you ...


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -