Ok,
///
Here is my base class (Note: it is a seperate assembly from my derived class)
///
namespace TSC.VXMLEngine
{
/// <summary>
/// Summary description for Engine.
/// </summary>
public class VXmlEngine
{
private static volatile VXmlEngine _instance = null;
private static object syncRoot = new object();
public int iObjectID = 0;
//declare delegates (event handlers) for event subscribers
public delegate void DialogAdded(object sender);
//declare event for to be handled by the delegates
public event DialogAdded OnDialogAdded;
public VXmlEngine()
{
//
// TODO: Add constructor logic here
//
}
// public property that can only get the single instance of this class.
public static VXmlEngine Instance
{
get
{
// only create a new instance if one doesn't already exist.
if (_instance == null)
{
// use this lock to ensure that only one thread is access
// this block of code at once.
lock(syncRoot)
{
if (_instance == null)
_instance = new VXmlEngine(); //create new instance of this class
}
}
// return instance where it was just created or already existed.
return _instance;
}
}
public void RaiseEventDialogAdded(VXmlDialog dialog)
{
//if anyone has subsribed, then notify them
if (OnDialogAdded != null)
{
OnDialogAdded(this, dialog);
}
}
}
}
///
//Here is my derived class
using System;
using System.IO;
using TSC.VXMLEngine;
namespace SurveyCast.Designer.Engine.Voice
{
/// <summary>
/// Summary description for VoiceEngine.
/// </summary>
public class VoiceEngine : VXmlEngine
{
private static volatile VoiceEngine _instance = null;
private static object syncRoot = new object();
public int iObjectID = 0;
// make the default constructor protected, so that no one can directly
create it.
protected VoiceEngine()
{
}
// public property that can only get the single instance of this class.
public static VoiceEngine Instance
{
get
{
// only create a new instance if one doesn't already exist.
if (_instance == null)
{
// use this lock to ensure that only one thread is access
// this block of code at once.
lock(syncRoot)
{
if (_instance == null)
_instance = new VoiceEngine(); //create new instance of this class
}
}
// return instance where it was just created or already existed.
return _instance;
}
}
}
}
//here is where I subscribe to the event:
_voiceEngine = VoiceEngine.Instance;
_voiceEngine.OnDialogAdded +=new
TSC.VXMLEngine.VXmlEngine.DialogAdded(_voiceEngine _OnDialogAdded);
"Jon Skeet [C# MVP]" wrote:
Opa <Op*@discussions.microsoft.com> wrote: I have a class (ClassB) that inherits from another class (ClassA) which has
a delegate and event.
I can see the events from ClassA in an intance object I create of ClassB.
I also subscribe to the event.
The problem is when I check go to "fire" the event in ClassA, the event
evaluates to null as if no one subscribed.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
My guess is that you're subscribing to events with one instance, then
trying to fire events with another. I'll have to see more code to know
for sure though.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too