If e.Cancel Then Exit Sub in Closing event

J

Just Me

I've seen this in example code:

Private Sub Studio_Closing(ByVal sender A..snip.. Handles MyBase.Closing

If e.Cancel Then Exit Sub

....snip...

It would make sense if Windows keeps doing Closing events even after it
receives an e.Cancel=true.

Is that the case?

Does the If make sense?

Can anyone shed some light on this?



Thanks for helpful comments
 
S

Samuel R. Neff

The event is broadcast by the multi-cast delegate just like any other
event. This delegate has no knowledge of the Cancel property or what
it is for. It always sends the event to all subscribed delegates.

Also, there are situations where you have multiple listeners of the
closing event and you want them to all fire off even if one of them
says to cancel.

If what you're doing doesn't need to run if something else cancelled,
then it's good practice to add this check at top of routine.

HTH,

Sam
 
J

Just Me

thanks a lot


Samuel R. Neff said:
The event is broadcast by the multi-cast delegate just like any other
event. This delegate has no knowledge of the Cancel property or what
it is for. It always sends the event to all subscribed delegates.

Also, there are situations where you have multiple listeners of the
closing event and you want them to all fire off even if one of them
says to cancel.

If what you're doing doesn't need to run if something else cancelled,
then it's good practice to add this check at top of routine.

HTH,

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top