locked
Waiting for an external database event RRS feed

  • Question

  • I have a workflow that does a number of activities. Completion of the workflow is dependent on reading an entry in a database. The appearance of that entry may take some time to appear. In some cases it will never appear. How do I design my workflow to 'look' for the entry for a period of time and if it does not appear complete the workflow regardless (setting the reply from this entry to failed). I don't want to have a simple while loop doing this. Ideally I'd like the workflow to wait for a period of hours only. But at that point I need it to complete regardless.

    I've been looking at using a parallel activity with a delay but I can't get that to work to achieve the above.

     

    Thursday, January 20, 2011 4:18 PM

Answers

  • Hi,

    Here is my idea
    First, create an asynchronous activity that will be able to query the entry. pass a delegete to the actually quering method. when the quering finished or timeout, the delegate will be executed and notify workflow.

    Second,Use Pick activity, place your asyn-activity in one pick, while place a Delay activity in another Pick branch. so that once the quering is timeout workflow will keep running to next activity.

    Hope this helps.
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Friday, January 28, 2011 10:12 AM
    Tuesday, January 25, 2011 7:08 AM

All replies

  • Hi,

    You should use a while branch for this. The while activity should poll the database, and then delay for a set time, before looping and polling again. The while branch will complete if the data is found, or the time for waiting expires.

    Regards,

    Alan


    http://www.CloudCasts.net - Community Webcasts Powered by Azure
    Thursday, January 20, 2011 4:52 PM
  • Thanks Alan, is there an easy way to configure the delay time period using a config file or do I have to write a custom activity to return what I want?
    Monday, January 24, 2011 5:47 PM
  • Hi,

    Here is my idea
    First, create an asynchronous activity that will be able to query the entry. pass a delegete to the actually quering method. when the quering finished or timeout, the delegate will be executed and notify workflow.

    Second,Use Pick activity, place your asyn-activity in one pick, while place a Delay activity in another Pick branch. so that once the quering is timeout workflow will keep running to next activity.

    Hope this helps.
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Friday, January 28, 2011 10:12 AM
    Tuesday, January 25, 2011 7:08 AM
  • Hi Andrew,

    I have tried this, but I'm having a problem.

    In my activity, I have a loop with a thread.sleep in it. Say it 20 takes seconds to complete. That's in one pick. If my delay, takes, say 5 seconds and its in the other pick, I'd expect this pick to end first. However, while this pci appears to end first (I've logged it), the first activity continues on regardless until the 20 seconds are up. I need that activity to finish based on the 5 seconds delay.

    Any suggestions?

     

    John C

     

    Friday, January 28, 2011 5:55 PM
  • Hi,

    Thread.Sleep in a workflow will not release the workflow thread and allow the workflow to enter the idle state. You will need to use an asynchronous code activity, or a composite activity using a workflow delay activity for this.

    Regards,

    Alan


    http://www.CloudCasts.net - Community Webcasts Powered by Azure
    Friday, January 28, 2011 6:21 PM
  • Hi Alan,

    I ahve an asynchronous activity. Basically replaced the call to therad.sleep with a call to

    System.Activities.Statements.

     

    Delay()

    with the same results. In other words this activity finishes regardelss of what I ahve in the first pick. If this activity is running asynchroniusly, does it not have to know that the delay code in the other pick has finished?

    Thanks JC

    Monday, January 31, 2011 11:55 AM