views:

770

answers:

1

I've been 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 should not matter at all).

Now, i can run the WF and it works fine, etc.. but it kicks off ASYNCRONOUSLY, so any results from the WF (good or bad) get lost page life cycle.

So .. after crying like an emo for ages, i stumbled across this gem on MSDN!

If you've click that link, that MSDN article says that in ASP.NET applications, we need to

  • Put the WorkflowRuntime into the Application state
  • The WorkflowRuntime instance has a ManualWorkflowSchedulerService added to it (whatever that is).
  • Use this application state workflow instance when required.

this is opposed to (the way i learnt)

  • Make the WorkflowRuntime a static object, that is first created when required.
  • Use this static WorkflowRuntime instance on the new workflow u are going to run.

So .. which way is better? do we need to stick it into the application? What are the differences between either/or?

I understand there's actually TWO questions here...

  • Application state vs static object (using lock/null or double null checking)
  • DefaultWorldFlowSchedulerService vs ManualWorldFlowSchedulerService

cheers!

EDIT:

  • First question is answered here.
  • Second question is answered below.
+3  A: 

I am not sure about your first question (although I suspect that they are equivalent). However, I am sure for the second question: You must definitely go with the ManualWorkflowSchedulerService. The main reasons are the following:

  • It's the only way to block the execution of the host application until the workflow instance becomes idle. Note that you have to explicitly use the RunWorkflow method.
  • ManualWorkflowSchedulerService reuse the thread that made the ASP.NET Web request to run the workflow instance. This ensures that at any time, the number of active threads in the workflow runtime equals the number of active Web requests in the ASP.NET process.

Check this sample for more.

Panos
cheers :) i might ask the first one in another place.
Pure.Krome
first answer is found elsewhere -> link to it, added above.
Pure.Krome