An stock data download class has a BarList to which it either adds new bars or updates and replaces the last bar when the last bar changes realtime. Whenever this download class adds a new bar to the BarList class or changes its last bar, it also calls its NotifyOnBarsAdded or NotifyOnBarChanges. I'm trying to get the notify methods to raise events so that the Canvas class which handles these events can redraw the last bar or entire chart depending on which notify method is called. The problem is that when the NotifyOnBarsAdded class is called i get a NullReferenceException as try to raise the event. I am raising the event like this: NotifyBarAdded(this, EventArgs.Empty)
. Is this incorrect? Here's the code:
public class BarList : List< Bar >
{
private int historyHandle;
public event EventHandler NotifyBarChanged;
public event EventHandler NotifyBarAdded;
public BarList(int historyHandle)
{
this.historyHandle = historyHandle;
}
public BarList()
{
// TODO: Complete member initialization
}
public void NotifyOnBarChange()
{
NotifyBarChanged(this,EventArgs.Empty);
}
public void NotifyOnBarsAdded()
{
NotifyBarAdded(this, EventArgs.Empty);
}
public long handle { get; set; }
}