fdncred's picture

Catching Close on NonForm Window

This 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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

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.

fdncred's picture

Thanks. That did it. Stupid of me not to look at the dozens of samples that do this. Sorry.

the Fiddler's picture

Hey, no prob, we are all learning here.