SonyWWS/ATF

ControlHostService Closing ignores CancelEventArgs.Cancel

Closed this issue · 3 comments

I've registered on the IMainWindow Closing Event to throw up a prompt if a document is dirty when the app closes. If I do want to throw up the prompt, I want to cancel the close event and call close myself when I'm done with the save.

However it seems ControlHostService mainForm_Closing sets e.Cancel to the result of !Close overwriting the value I set. I think ln718 needs to be e.Cancel = e.Cancel || !Close();

Does that sound right?

Also when the mainform does not cancel and an intervening operation closes the mainform, it seems to interrupt the layout saving causing an exception in subsequent loads. My suggested change in the original post fixes that as well.

Ron2 commented

Good point, Colin. I'll check in your change shortly. Thanks for the good suggestion.

I assume you made sure that your event handler gets the Closing event before ControlHostService. I wish that the ordering of the listeners didn't matter, but there's no way around that restriction given the IControlHostClient interface. (There's no "CanClose" method.)

In my use case it is.