locked
Invoke long running workflow from web page

    Question

  • Hi,

     

    I have a workflow that needs to be started by clicking on a link on a web page.

     

    The following activities in the workflow take around 30 minutes to complete.

     

    I don't want the user to wait 30 minutes before their page returns.

     

    How can I implement the workflow so that it runs in the background? Do I need to use WCF or something?

     

    Monday, January 21, 2008 2:57 AM

Answers

  • WorkflowInstance.Start()  is a asynchronized function, so in the click event handler function of the web component, you just create the workflow instance, and let it start. Then it is OK for you send the page back, to let user control the page. The workflow instance will run in the backgound asynchronized, and you should hold the instance in some static way, to retrieve it later.

    Monday, January 21, 2008 6:58 AM

All replies

  • I am not sure what is your expected user scenario. Do you want user to get signaled that your workflow is running in background just after his/her clicking, or get informed again when the workflow finished to let user know the result. If in the previous case, you just need to render web page before the workflow get started. If in the latter case, I guess you can use Ajax to update your web page later, try to use WCF AjaxSmile. Or try other ways to inform the user, like email or something, if you don't expect user will keep the web page open for 30 minutes to get the result.

    Monday, January 21, 2008 3:46 AM
  •  

    This is the case:

     

    Web page > WCF Service (.svc) > Workflow (runs for a long time)

     

    When the workflow finishes, I'll just email the user or use AJAX to constantly update the page, showing the current state of the workflow. It doesn't really matter. What matters is returning the control to the user as soon as the workflow starts.

     

    How can I implement it?

    Monday, January 21, 2008 4:35 AM
  • WorkflowInstance.Start()  is a asynchronized function, so in the click event handler function of the web component, you just create the workflow instance, and let it start. Then it is OK for you send the page back, to let user control the page. The workflow instance will run in the backgound asynchronized, and you should hold the instance in some static way, to retrieve it later.

    Monday, January 21, 2008 6:58 AM
  • Does WorkflowIsnatce.Start() become synchronized if using the manulworkflowschedular? As I undertstand it uses the same thread, so does that mean the page will not return until the workflow has finished?


    Monday, January 21, 2008 4:38 PM
  • Right, ManualWorkflowSchedulerService is synchronized, and the page will wait until workflow finishes. While the default way is asynchronized. That is you don't have to wait the workflow to be finished.

     

    Please look at the reference

    http://msdn2.microsoft.com/en-us/library/system.workflow.runtime.hosting.manualworkflowschedulerservice.aspx

    Tuesday, January 22, 2008 3:38 AM