I have a weird random NPE error when dealing with ManualResetEvent.WaitOne(). Here's my code.
I have a method that creates ManualResetEvent object and then it passes it down to the Windows Workflow Foundation (WWF) workflow instance as one of the dependency parameter (manualResetEvent) and then I go into manualResetEvent.WaitOne() API.
ManualResetEvent manResetEvt = new ManualResetEvent(false);
Dictionary<String, Object> wfArgs = new Dictionary<string, object>();
wfArgs["manualResetEvent"] = manResetEvt;
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(MyWWFProcess), wfArgs);
instance.Start();
manResetEvt.WaitOne();
When the job is done within WWF, I simply call manualResetEvent.set().
if (this.manualResetEvent != null)
{
this.manualResetEvent.Set();
}
All these compile well and while running, I see that the flow gets into the WWF as expected and the caller does wait on WaitOne() call too.
The moment the WWF invokes manualResetEvent.Set() to notify the caller, I see an NPE exception with the caller NOT WWF.
System.NullReferenceException: Object reference not set to an instance of an object.
I really don't know where this exception arises from. When I debug this code in VS IDE, all works well but only when with the application in the Release mode, I see this exception.
What am I doing wrong here?