You can invoke the event:
public class MyClass {
private void InvokeCustomEvent(string myMessage) {
if (customEvent != null)
customEvent.Invoke(this, new CustomArgs(myMessage));
}
private void InvokeCustomEvent() {
if (customEvent != null)
customEvent.Invoke(this, new CustomArgs());
}
}
Also, change access modifiers of those two constructors of
CustomArgs
to
internal
, because there is no situation where you can call them outside of the assembly. This is because, even by syntax, you can only invoke any event in the declaring class, not even in derived classes.
I even demonstrated that the methods
InvokeCustomEvent
should be used only in this class, so I've shown the
private
access modifiers.
Please see my recent answer for more detail:
Since we have multicast delegates, why do we need events?[
^]
The users of the class instance only have access to the event object to use it to add one or more event handlers via "+=" (or remove via "-=" which is relatively rarely used). The invocation of the even always calls the whole list of event handles from the invocation list of the event.
—SA