I have a library which fires events through this code:
public delegate void ChangedEventHandler(String currentFunction, String PCDMessage, ePcdEventType pcdEventType, ePcdEvent pcdEvent);
public event ChangedEventHandler OnStatusChange;
and
protected virtual void RaiseEvent(String strCurrentFunction, String strMessage, ePcdEventType pcdEventType, ePcdEvent pcdEvent)
{
if (OnStatusChange != null)
OnStatusChange(strCurrentFunction, strMessage, pcdEventType, pcdEvent);
}
everything works fine but when I fire the event from the following backgroundWorker
bwExecute = new BackgroundWorker();
bwExecute.DoWork += BwExecute_DoWork;
bwExecute.RunWorkerCompleted += Bg_RunWorkerCompleted;
object[] parameters = new object[] { currentFunc, partProgramFilename, varsValuesList};
bwExecute.RunWorkerAsync(parameters);
and the RaiseEvent are fired in the ExecuteJob routine just as they are fired in the other part of the code.
So in short ONLY when called inside the backgroundWorker the OnStatusChange when called inside the RaiseEvent is ALWAYS NULL and so the event is not fired. I always call the RaiseEvent(...) in the same way both outside and inside the background worker. Now understood the problem, what is the solution?
**EDIT** I'm using C# WPF but I don't think this makes any difference.
Thank for any help Patrick