Alex F
Alex F

Reputation: 43321

Sender of static EventHandler event

I have class with static EventHandler event:

public static event EventHandler MyEvent;

static void RaiseEvent()
{
    EventHandler p = MyEvent;

    if (p != null)
    {
        p(null, EventArgs.Empty);
    }
}

Since I don't have any this object which can be used as event sender, I raise this event with sender = null. Is it OK to have this parameter set to null, according to .NET programming guidelines? If not, what object can I use as a sender?

Upvotes: 17

Views: 6445

Answers (1)

oakio
oakio

Reputation: 1898

Event Design

On static events, the sender parameter should be null

Source: https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms229011(v=vs.100)

Upvotes: 26

Related Questions