
Catching Close on NonForm Window
Posted Friday, 28 January, 2011 - 14:38 by fdncred inThis may be more of a C# question than OpenTK. I have a NonForm application that has a GameWindow derived class. I have the typical contructor:
public HeightMap() : base(nWindowWidth, nWindowHeight, GraphicsMode.Default, "Height Map")
I want to do some cleanup before exiting. I've tried the following and none get called:
~HeightMap() {...} public void Dispose() {...} protected virtual void Dispose(bool disposing) {...}
I can catch the Esc key and do cleanup but I'm not sure how to catch the event when the user clicks the Windows X to close the window.
What am I missing?
Thanks in advance.


Comments
Re: Catching Close on NonForm Window
Hook the GameWindow.Unload event and do your cleanup there. There is also GameWindow.Closing that you can use to confirm whether the GameWindow should really close.
Finalizers should not execute critical code, since they may not be called in all circumstances. IDisposable should be used to clean up native resources or to provide deterministic cleanup (via 'using' regions). In most other circumstances, the garbage collector will take care of itself.
Re: Catching Close on NonForm Window
Thanks. That did it. Stupid of me not to look at the dozens of samples that do this. Sorry.
Re: Catching Close on NonForm Window
Hey, no prob, we are all learning here.