I have a static class which I've designed. I'm attempting to add an event to the static class in order to provide some notifications about what's going on to the other parts of the program. The problem is, EventHandler requires a System.Object reference for the sender, and the "this" keyword can't be used. So, I'm stuck on how to provide the EventHandler an Object reference. I tried using typeof(), but it crashes due to a null reference exception.

Basically, the class has:

public static class Lahman


//... snip ...

/// <summary>

/// Lahman database event handler.

/// </summary>

public static event EventHandler<LahmanEventArgs> RaiseLahmanEvent;

And I'm trying to raise that event inside the Lahman class like:

RaiseLahmanEvent(typeof(Lahman), new LahmanEventArgs("Adding Lahman Master record for " + theRecord.NameLast + ", " + theRecord.NameFirst));

(well, the above is the last thing I tried. That's what crashes, though)

Re: Visual C# General Raising an event from a static class


I dont know if this is the best design.. but

does the entire class need to be static

i.e. create a regular class with static members;

if you dont want instances being created from outside the class, then override the default constructor with a

private constructor;

hope this is of use,