المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : CancelEventArgs - multiple subscribers



C# Programming
06-30-2009, 01:12 AM
Whenever I use CancelEventArgs I iterate over the invocation list and check the Cancel state for each subscriber and break if true, so if any subscriber cancels the process, it is sure to be cancelled and further subscribers will not get called.

I'm needing to customise the BackgroundWorker, so had a quick look at the source code for it and was suprised to find that it doesn't use this policy. If there is more than one subscriber, then only the last one in the invocation list is able to properly set the Cancel that is carried through to the RunWorkerCompletedEventArgs. If the first subscriber sets Cancel to true, the second will still get called and can set it to false!

What would you say is the best practice - my way, or Microsoft's, or is there some in between method that would be better?

Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn (http://www.codeproject.com/Members/Luc-Pattyn))
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia (http://uncyclopedia.org/wiki/.NET))
Why are you using VB6? Do you hate yourself? (Christian Graus (http://www.codeproject.com/script/Membership/View.aspx?mid=6556))