17

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?

Alex F
  • 42,307
  • 41
  • 144
  • 212

1 Answers1

26

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)

Pang
  • 9,564
  • 146
  • 81
  • 122
oakio
  • 1,868
  • 1
  • 14
  • 21