ASP.NET and Windows Workflow (WF) - should this be injected into the application state?

I'm trying to use WF in my ASP.NET application (actually it's ASP.NET MVC ... but the fact that it's MVC instead of WebForms doesn't matter at all).

Now I can run WF and it works fine, etc., but it runs ASYNCHRONOUSLY, so any WF results (good or bad) lose the page lifecycle.

I found an MSDN article that says that in ASP.NET applications, we need

  • Put WorkflowRuntime

    in app state
  • WorkflowRuntime

    Added in the instance ManualWorkflowSchedulerService

    (whatever it is).
  • Use this instance of the application workflow as needed.

This is different from how I learned to do it:

  • Let the WorkflowRuntime be a static object that is first instantiated when required.
  • Use this static WorkflowRuntime instance in the new workflow that you are about to start.

So ... which way is better? Do I need to embed it in the application? What are the differences between them?

I understand that there are actually two questions here ...

  • Application state against static object (using lock / null or double zero check )
  • DefaultWorkFlowSchedulerService vs ManualWorkFlowSchedulerService

Hooray!

EDIT:

  • The answer to the first question is here .
  • The answer to the second question is below.
+1


source to share


1 answer


I'm not sure about your first question (although I suspect they are equivalent). However, I am confident on the second question: you should definitely go with ManualWorkflowSchedulerService

. Main reasons:

  • This is the only way to block the execution of the host application until the workflow instance is idle. Note that you must use the method explicitly RunWorkflow

    .
  • ManualWorkflowSchedulerService

    reuse the thread that caused the ASP.NET web request to start the workflow instance. This ensures that at any given time, the number of active threads in the worker workflow environment is equal to the number of active web requests in the ASP.NET process.


Check out this sample for more.

+4


source







All Articles