Search code examples
c#workflow-foundation-4workflow-foundationworkflow-activityworkflowservice

How to use Bookmark without user input?


I'm new to Windows Workflow and am using 4.5 to create a long-running workflow. I did a lot of online search, trying to find a way to create a Bookmark and ResumeBookmark without user input. The info I've read so far all requires a Console.ReadLine (user input) in order to resume a Bookmark. Is Bookmark only used for human input? I'm using the Delay Activity for now, but would like to use Bookmark.

My Workflow.xaml is like this:

  1. Send email to reviewers, who are asked to complete their respective task. The email is just a notification. There is no approve or reject button.

  2. Delay Activity. This is to make the workflow persist in the persistence database.

  3. Check another database to see if some data are updated by reviewers.

  4. Delay Activity again, if reviewers have not updated the data.

  5. Send email to approver. if the data are updated. Approver's response will be recorded in the database. The email is just a notification.

  6. Delay Activity again, waiting for approver's updating response in database.

and so on.

I'd really appreciate your help.


Solution

  • Bookmarks do not require user input.

    You create a bookmark inside an activity:

    context.CreateBookmark("bookmarkName", new BookmarkCallback(OnResumeBookmark));
    

    Where "OnResumeBookmark" is a method in your activity.

    Then when you resume the workflow you use this:

    WorkflowApplication wfApp= new WorkflowApplication(new NameOFWorkflow());
    
    wfApp.Run();
    
    wfApp.ResumeBookmark("bookmarkName");
    

    OnResumeBookmark will then execute.

    Here is a fuller version http://msdn.microsoft.com/en-us/library/ee191721(v=vs.110).aspx

    The stuff in there about console.read is just a way to show you how the bookmark name can be a variable rather than a string:

    context.CreateBookmark(BookmarkName.Get(context),  <-- get name from the InArgumen