Hello gurus,
I have designed simple state machine workflow that contains a few states: intial state is (A) "Waiting for documents", (B) second state "Calculating", (C)last "Done";
State (A) has an event driven activity which handles an external event called DocumentsReceived if this event is invoked, the state would be set to state (B) "Calculating";
State (B) has an event driven activity which handles an external event called CalculationDone if this event is invoked, the state would be set to state (C) "Done";
This workflow runs in asp.net enveroment:
- A runtime is started in application_start event and stopped in application_stop event of the HttpApplication;
- The workflow is created as follows initially when the web page (asp.net mvc view) is loaded:
var instance = WorkflowRuntimeHandle.CreateWorkflow(type);
instance.Start();
WorkflowRuntimeHandle.GetService().RunWorkflow(instance.InstanceId);
instance.Unload();// persist the workflow
//The runtime is configured with SqlPersistanceService so the workflow gets persisted;
3.There is a link on that web page (asp.net mvc view) which calls a controller action that reloads the workflow and fires an external event as follows:
3.1. var instance = WorkflowRuntimeHandle.GetWorkflow(id).Load();
3.2. incomeCalculationService.OnDocumentReceived(GetExternalDataEventArgs(instance.InstanceId));
3.3. WorkflowRuntimeHandle.GetService<ManualWorkflowSchedulerService>().RunWorkflow(instance.InstanceId);
3.4. var stateMachineWorkflowInstance = new StateMachineWorkflowInstance(instance.WorkflowRuntime, instance.InstanceId);
3.5. if (stateMachineWorkflowInstance.CurrentStateName=="Calculating")
3.6. return RedirectToAction(ActionName.Calculating, new { id });
4.The problem is that it takes two clicks for the line 3.5. to be true, why is that?
Any comments and suggestions are welcome,
Cullen