ok, I tried to include as little code as possible. The app uses three
different assemblies as follows:
//
//Here are the the code snippets of the classes in my TSC.VXMLEngine Assembly
//In a nutshell the VXmlApplication is a singleton class
//which has one VXmlDocuments object containing 0 -n VXmlDocument objects.
Each VXmlDocument contains 0 - n VXmlDialog objects
// when a VXmlDialog is added. I am calling RaiseEventDialo gAdded of the
VXmlApplication Instanace which should fire the event
//but it doesn't
using System;
namespace TSC.VXMLEngine
{
public class VXmlApplication
{
private static volatile VXmlApplication _instance = null;
private static object syncRoot = new object();
public int iObjectID = 0;
//declare delegates (event handlers) for event subscribers
public delegate void DocumentAddedHa ndler(object sender, VXmlDocument
document);
public delegate void DialogAdded(obj ect sender, VXmlDialog dialog);
//declare event for to be handled by the delegates
public event DocumentAddedHa ndler OnDocumentAdded ;
public event DialogAdded OnDialogAdded;
private static volatile VXmlDocuments _vxmlDocuments;
// make the default constructor protected, so that no one can directly
create it.
protected VXmlApplication ()
{
if (_vxmlDocuments == null)
_vxmlDocuments = new VXmlDocuments() ;
}
// public property that can only get the single instance of this class.
public static VXmlApplication 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 VXmlApplication (); //create new instance of this class
}
}
}
// return instance where it was just created or already existed.
return _instance;
}
}
public VXmlDocuments Documents
{
get
{
return _vxmlDocuments;
}
}
internal void RaiseEventDocum entAdded(VXmlDo cument document)
{
//if anyone has subsribed, then notify them
if (OnDocumentAdde d != null)
{
OnDocumentAdded (this, document);
}
}
internal void RaiseEventDialo gAdded(VXmlDial og dialog)
{
//if anyone has subsribed, then notify them
if (OnDialogAdded != null)
{
OnDialogAdded(t his, dialog);
}
}
}
public class VXmlDocument
{
private VXmlDialogs _dialogs;
private DocumentTypes _documentType;
private VXmlApplication _ownerApplicati on;
private string _name;
private string _fileName;
public VXmlDocument()
{
_dialogs = new VXmlDialogs();
}
public VXmlDialogs Dialogs
{
get
{
return _dialogs;
}
}
public string Name
{
get
{
return _name;
}
set
{
_name = value;
_fileName = _name + ".vxml";
}
}
}
public class VXmlDocuments
{
public VXmlDocuments()
{
}
public int Add(VXmlDocumen t value)
{
VXmlApplication .Instance.Raise EventDocumentAd ded(value);
return base.List.Add(v alue as VXmlDocument);
}
}
public abstract class VXmlDialog
{
public VXmlDialog()
{
}
}
public class VXmlDialogs
{
public VXmlDialogs()
{
}
public int Add(VXmlDialog value)
{
VXmlApplication .Instance.Raise EventDialogAdde d(value);
return base.List.Add(v alue as VXmlDialog);
}
}
}
//Here is my derived classes in a different assembly
using System;
using System.IO;
using TSC.VXMLEngine;
namespace SurveyCast.Desi gner.Engine.Voi ce
{
public class VoiceEngine : VXmlEngine
{
private static volatile VoiceEngine _instance = null;
private static object syncRoot = new object();
public int iObjectID = 0;
private SurveyCast.Desi gner.Engine.Voi ce.VoiceSurveyP roject _currentSurvey;
// 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;
}
}
public VoiceSurveyProj ect CreateSurveyPro ject()
{
//_currentSurvey = VoiceSurveyProj ect.Create();
_currentSurvey = new VoiceSurveyProj ect();
_currentSurvey. OnDialogAdded +=new
TSC.VXMLEngine. VXmlApplication .DialogAdded(_c urrentSurvey_On DialogAdded);
return _currentSurvey;
}
}
public class VoiceSurveyProj ect : VXmlApplication
{
private VXmlDocument _currentDocumen t;
//prevent direct creation
public VoiceSurveyProj ect()
{
}
public VXmlDocument CurrentDocument
{
get
{
return _currentDocumen t;
}
set
{
_currentDocumen t = value;
}
}
public static VoiceSurveyProj ect Create()
{
return new VoiceSurveyProj ect();
}
public void Load()
{
VXmlDocument document = new VXmlDocument();
document.Name = "Document1" ;
_currentDocumen t = document;
base.Documents. Add(document);
}
public void AddSingleChoice ()
{
VoiceSingleChoi ce singleChoice = new VoiceSingleChoi ce();
_currentDocumen t.Dialogs.Add(s ingleChoice);
}
}
public class VoiceSingleChoi ce : VXmlDialog
{
public VoiceSingleChoi ce()
{
}
}
}
//finally, here is my windows application snippet
// note: the btnAddDialog_Cl ick add a VoiceSingleChoi ce object which is a
VXmlDialog
using SurveyCast.Desi gner.Engine.Voi ce;
using TSC.VXMLEngine;
namespace SurveyCast.Desi gner.GUI.Voice
{
public class FormMain : System.Windows. Forms.Form
{
public FormMain()
{
AddEvents();
StartEngine();
}
private void StartEngine()
{
_voiceEngine = VoiceEngine.Ins tance;
_survey =_voiceEngine.C reateSurveyProj ect();
_survey.OnDialo gAdded+=new
TSC.VXMLEngine. VXmlApplication .DialogAdded(_s urvey_OnDialogA dded);
_survey.Load();
}
private void btnAddDialog_Cl ick(object sender, System.EventArg s e)
{
VoiceSingleChoi ce singleChoice = new VoiceSingleChoi ce();
_survey.Current Document.Dialog s.Add(singleCho ice);
}
private void _survey_OnDialo gAdded(object sender, VXmlDialog dialog)
{
// I never get here
}
}
}
Whew! Hope you can figure out what I am trying to do.
Thanks for your help
"Jon Skeet [C# MVP]" wrote:
Opa <Op*@discussion s.microsoft.com > wrote: I wasn't sure if it would get lost in the stack.
It won't. New posts will always show up as new posts.
Yes, I am still having this problem.
I've tried for hours to figure it out. I'm still no where, can you help.
Certainly. Just post a short but complete program which demonstrates
the problem, and I'm sure it won't be too hard to fix.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too