Don't mark
onChange
as
event
. If you mark it as
event
, you cannot call it as you tried. Also, it's not necessary to use
lock
while adding an event handler. And if
OnChange
is public, it's not necessary to make
onChange
also public, unless you need to use it at another location (but I don't think you do, because you already have OnChange). So, replace it with this:
private EventHandler<MyArgs> onChange;
public event EventHandler<MyArgs> OnChange
{
add
{
onChange += value;
}
remove
{
onChange -= value;
}
}
And to call it:
public void Raise()
{
if (onChange != null)
{
onChange(this, new MyArgs(42));
}
}