I have a window where I need to fire a specific method when this window closing, I did:
public FooWindow()
{
Closing += (x, y) => Exit();
}
private void Exit()
{
if (someVariable)
{
Environment.Exit(1);
}
else
{
Close();
}
}
when the Exit event is called the close method is reached but I get
System.InvalidOperationException: Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed.
what am i doing wrong?
Show. Anyway why do you exit the app on closing? Wouldnt this hapen anyway? Or is your form called from another one? In thie latter case you shpuld close the parent window, not the program. - HimBromBeere