views:

144

answers:

2

I'm working with C# and CF and I need to use a MessageWindow to intercept Windows Messages.

There may be scenarios where the MessageWindow dies unexpectedly. This is a problem for me as the messages it is receiving are kinda important and i'd like to log the fact the Window has died.

Unfortunately I don't see any way (at least not in Managed API) that I can get this kind of notification. Can anyone help?

+1  A: 

Some ideas:

Can you "ping" the MessageWindow by generating an special message of your own every X interval? then check for this "ping" that way you can be sure to detect destruction within approx. X time.

Or can you override the Dispose or Finalize calls? if these get called. I am also assuming no exception is being thrown.

CJCraft.com
Aye I could ping, MessageWindow doesn't implement IDisposable (at a base level) and finalise wont be particulary deterministic, nor do I really wanna touch other objects (like a logger) in a finaliser.
Quibblesome
+1  A: 

Not sure what you mean by "dies" but generally speaking when a Window is destroyed (including the one underlying a MessageWindow) you will get a WM_DESTROY call. Can you look for that in the WndProc?

ctacke
I eventually just created it on a background thread and ran Application2.Run() from OpenNETCF.Logging code lives underneath so we log when it exits.
Quibblesome