I have an MVVM Project and need to run some methods when th VM is destroyed. I'm trying this:
public class MyClass
{
public void MyCleanUpmethod(object p)
{
// My Clean up proccess here
....
}
~ MyClass()
{
MyCleanUpmethod(new object());
}
}
My problem is that ~ MyClass() only runs when close the entire application, I need to run it when MyClass is not used anymore during current procces.
It mean if MyClass is used as Datacontext of a window ~ MyClass() must run when the window closes, if an instance of MyClass is used in other things diferent as Datacontext, ~ MyClass() must run too
How can I do that ?