I'm trying to raise events in my abstract class and my derived class and have them come out to the same event in main. Is this possible? With the code below, I set a breakpoint in the two raise events and I see the bar raise but never the foo and the actual event in main is never called due to OnDataReceived being null. What am I doing wrong? If I try to make the bar event abstract and the Raise Function virtual in bar and override both in my derived classes then I get an error for the OnDataReceived in bar not being left side of += or -=.
Here is basically what I have:
public abstract class bar
{
public event DataReceivedHandler OnDataReceived;
protected void RaiseDataReceivedEvent(EventArgs e)
{
if (OnDataReceived != null)
OnDataReceived(this, e);
}
/// <summary>
/// A global event that will happen for all "bar" derived classes
/// </summary>
private void globalEvent()
{
//Raise this event for the derived class here.
RaiseDataReceivedEvent(new EventArgs());
}
}
public class foo : bar
{
public foo()
{
}
/// <summary>
/// A specific event that will happen only for this derived class
/// </summary>
private void fooSpecificEvent()
{
//Raise this event for the derived class here
RaiseDataReceivedEvent(new EventArgs());
}
}
public class Main
{
bar specificProduct = new foo();
public Main()
{
specificProduct.OnDataReceived += specificProduct_OnDataReceived;
}
void specificProduct_OnDataReceived(object sender, IttsDataReceivedEventArgs e)
{
//Here I want to process events from both fooSpecificEvent and globalEvent calls to RaiseDataReceivedEvent
}
}
globalEvent& 'fooSpecificEvent' called? - Serj-Tmmainprogram that demonstrates the problem? - BJ Myers