Reputation: 43321
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
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