I am using wpf. I want to:
- Close a window
- Wait for all desendents finish cleanup
- Then run some other code
Currently, I use the Unloaded
event to cleanup some unmanaged resources.
However, Based on observation and documentation, the Unloaded
event is fired top to bottom:
- Window
Unloaded
- Children
Unloaded
- Grandchildren
Unloaded
- ...
Which dose not allow me to do what I want.
And Window.Closed
is even fired before Unloaded
.
Is there any built-in solution for this problem?
Or do I have to roll my own?
e.g. implement IDisposable for all of my controls. Like this answer.