0

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?

Quibblesome
  • 25,225
  • 10
  • 61
  • 100

2 Answers2

1

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.

Chris Craft
  • 5,285
  • 6
  • 46
  • 63
  • 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 May 13 '09 at 09:39
1

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
  • 66,480
  • 18
  • 94
  • 155
  • 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 May 13 '09 at 09:41