|
Hi,
I have searched the forum for answers to this question, but was unable to find it. I apologise in advance if this has already been answered somewhere...
The problem I am experiencing at the moment is that when I raise the WorkflowStarted event in my ASP.Net page it executes twice. I have investigated this in both Sequential and State Machine workflows. I have also tried running the page in debug and non debug mode, and the same behaviour occurs.
What is happening is that when the WorkflowInstance start method is called, the WorkflowStarted event executes once, and then immediately executes again, once the second execute has completed control is returned back to the calling routine.
If anyone has experienced this issue and found a solution to it then your help will be greatly appreciated.
Thanks
Steve
Please find a snippet of the code below that I have written in my ASP.Net page (The workflow runtime is started in the Global.asax file).
protected void Page_Load(object sender, EventArgs e)
{
ASP.global_asax.workflowRuntime.WorkflowStarted += new EventHandler<WorkflowEventArgs>(WorkflowRuntime_WorkflowStarted);
ASP.global_asax.workflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(WorkflowRuntime_WorkflowTerminated);
ASP.global_asax.workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(WorkflowRuntime_WorkflowCompleted);
if (!Page.IsPostBack)
{
SqlWorkflowPersistenceService sqlPersistence = ASP.global_asax.workflowRuntime.GetService<SqlWorkflowPersistenceService>();
}
ASP.global_asax._RequestService = ASP.global_asax.workflowRuntime.GetService<RequestLocalServices.RequestService>();
if (ASP.global_asax._RequestService == null)
{
ExternalDataExchangeService dataService = ASP.global_asax.workflowRuntime.GetService<ExternalDataExchangeService>();
ASP.global_asax._RequestService = new RequestLocalServices.RequestService();
dataService.AddService(ASP.global_asax._RequestService);
}
}
void WorkflowRuntime_WorkflowStarted(object sender, WorkflowEventArgs e)
{
//Just some dummy code
int i=1+1;
}
//UpdateGridViewItem(e.WorkflowInstance,"","Completed");
}
protected void BtnClick_Click(object sender, EventArgs e)
{
Button currentButton = sender as Button;
ManualWorkflowSchedulerService scheduler = ASP.global_asax.workflowRuntime.GetService<ManualWorkflowSchedulerService>();
Guid workflowInstanceId = Guid.Empty;
if (Session["WorkflowInstanceID"] != null) workflowInstanceId = new Guid(Session["WorkflowInstanceID"].ToString());
if (currentButton.ID == this.ButtonCreateRequest.ID)
{
int requestId = int.Parse(this.TextBoxRequestID.Text);
// Start the Order Workflow
workflowInstanceId = this.StartWorkflow(requestId);
Session[ "WorkflowInstanceID"] = workflowInstanceId;
Session[ "RequestID"] = requestId;
// Raise an RequestCreated event using the Request Service
ASP.global_asax._RequestService.RaiseRequestCreatedEvent(requestId, workflowInstanceId);
scheduler.RunWorkflow(workflowInstanceId);
}
private System.Guid StartWorkflow(int requestId)
{
ManualWorkflowSchedulerService scheduler =
ASP.global_asax.workflowRuntime.GetService<ManualWorkflowSchedulerService>();
// Create a new GUID for the WorkflowInstanceId
System. Guid WorkflowInstanceId = System.Guid.NewGuid();
WorkflowInstance instance = ASP.global_asax.workflowRuntime.CreateWorkflow(typeof(OrderWorkflows.AbsenceRequest), null, WorkflowInstanceId);
instance.Start();
scheduler.RunWorkflow(WorkflowInstanceId);
// Return the WorkflowInstanceId
return WorkflowInstanceId;
}
|