Click here to Skip to main content
15,884,001 members
Home / Discussions / C#
   

C#

 
AnswerRe: Showing a custom balloon tip icon Pin
Curry Francis25-Jul-16 1:53
Curry Francis25-Jul-16 1:53 
AnswerRe: Showing a custom balloon tip icon Pin
Ravi Bhavnani25-Jul-16 5:36
professionalRavi Bhavnani25-Jul-16 5:36 
QuestionLINQ Join Result Is Null Pin
MadDashCoder24-Jul-16 9:15
MadDashCoder24-Jul-16 9:15 
AnswerRe: LINQ Join Result Is Null Pin
Mycroft Holmes24-Jul-16 14:30
professionalMycroft Holmes24-Jul-16 14:30 
GeneralRe: LINQ Join Result Is Null Pin
MadDashCoder24-Jul-16 18:24
MadDashCoder24-Jul-16 18:24 
AnswerRe: LINQ Join Result Is Null Pin
Richard Deeming24-Jul-16 22:31
mveRichard Deeming24-Jul-16 22:31 
GeneralRe: LINQ Join Result Is Null Pin
MadDashCoder25-Jul-16 4:51
MadDashCoder25-Jul-16 4:51 
QuestionWhat is the correct code to invoke subscribers for an event? Pin
User 1106097923-Jul-16 21:16
User 1106097923-Jul-16 21:16 
Let's assume we have something like this:
C#
public class Person : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged([CallerMemberName]string propertyName = null)
    {
        // Is it really needed, to make a copy?  *1) 
        var handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    // ....
}
*1) Copy of the subscribers really needed?
A lot of time in forums like CP I read we need to make a copy of the subscribers before invoke the handlers. Argumentation: This because theoretically the subscribers can unsubscribe in between...

My doubts, respectively I see only arguments why not to copy:
a.) In a some lot (in most?) of MSDN examples, no copy will be made. So, when MSDN does not do it why should I do it?
b.) In case someone unsubscribes he is not longer interested in the event. Why should I notify him then longer?
c.) My opinion is, that it can be dangerous to inform a subscriber while he unsubscribed and therefore does not expect notifications any longer.

[Edit] Thank you BillWoodruff Smile | :)
Ok, a problem I see now in case I do not make a copy:
In bewteen (if PropertyChanged != null) and invoking PropertyChanged(...) it is possible that one does unsubscribe. Probably this Point is solved in c#6 by using (PropertyChanged?.Invoke(...)

But still "c.)" above is critical I think...(?) and the subscriber has to be aware that even after unsubscribing he can get notifications.

Comments / corrections / notes will be very appreciated.
Thank you in advance.

modified 19-Jan-21 21:04pm.

AnswerRe: What is the correct code to invoke subscribers for an event? Pin
BillWoodruff23-Jul-16 21:31
professionalBillWoodruff23-Jul-16 21:31 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
User 1106097923-Jul-16 21:54
User 1106097923-Jul-16 21:54 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
BillWoodruff23-Jul-16 22:03
professionalBillWoodruff23-Jul-16 22:03 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
Richard MacCutchan24-Jul-16 1:31
mveRichard MacCutchan24-Jul-16 1:31 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
BillWoodruff24-Jul-16 2:59
professionalBillWoodruff24-Jul-16 2:59 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
Richard MacCutchan24-Jul-16 4:28
mveRichard MacCutchan24-Jul-16 4:28 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
Richard Deeming24-Jul-16 22:15
mveRichard Deeming24-Jul-16 22:15 
AnswerRe: What is the correct code to invoke subscribers for an event? Pin
Pete O'Hanlon23-Jul-16 23:43
mvePete O'Hanlon23-Jul-16 23:43 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
User 1106097923-Jul-16 23:53
User 1106097923-Jul-16 23:53 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
Pete O'Hanlon24-Jul-16 5:51
mvePete O'Hanlon24-Jul-16 5:51 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
BillWoodruff24-Jul-16 23:04
professionalBillWoodruff24-Jul-16 23:04 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
Richard Deeming25-Jul-16 0:05
mveRichard Deeming25-Jul-16 0:05 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
User 1106097925-Jul-16 0:30
User 1106097925-Jul-16 0:30 
SuggestionRe: What is the correct code to invoke subscribers for an event? PinPopular
Maarten197725-Jul-16 3:16
Maarten197725-Jul-16 3:16 
GeneralRe: What is the correct code to invoke subscribers for an event? Pin
User 1106097925-Jul-16 3:58
User 1106097925-Jul-16 3:58 
QuestionTime of action in [Date] [Time] [Action] Pin
mmiklauz23-Jul-16 10:01
mmiklauz23-Jul-16 10:01 
AnswerRe: Time of action in [Date] [Time] [Action] Pin
Mycroft Holmes23-Jul-16 14:20
professionalMycroft Holmes23-Jul-16 14:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.