WorkflowApplication.GetBookmarks Method ()

.NET Framework (current version)

Returns the collection of bookmarks for the workflow instance.

Namespace:   System.Activities
Assembly:  System.Activities (in System.Activities.dll)

public ReadOnlyCollection<BookmarkInfo> GetBookmarks()

Return Value

Type: System.Collections.ObjectModel.ReadOnlyCollection<BookmarkInfo>

A read-only collection of bookmarks for the workflow instance.

If this operation does not complete within 30 seconds, a TimeoutException is thrown.

The following example creates a workflow that uses a ReadLine activity that creates a Bookmark. The workflow is started, and once the Bookmark is created and the workflow goes idle, GetBookmarks is called. When the workflow is completed, the following output is displayed to the console.

What is your name? BookmarkName: UserName - OwnerDisplayName: ReadLineSteveHello, Steve
public sealed class ReadLine : NativeActivity<string>
    public InArgument<string> BookmarkName { get; set; }

    protected override void Execute(NativeActivityContext context)
        // Create a Bookmark and wait for it to be resumed.
            new BookmarkCallback(OnResumeBookmark));

    // NativeActivity derived activities that do asynchronous operations by calling 
    // one of the CreateBookmark overloads defined on System.Activities.NativeActivityContext 
    // must override the CanInduceIdle property and return true.
    protected override bool CanInduceIdle
        get { return true; }

    public void OnResumeBookmark(NativeActivityContext context, Bookmark bookmark, object obj)
        // When the Bookmark is resumed, assign its value to
        // the Result argument.
        Result.Set(context, (string)obj);
Variable<string> name = new Variable<string>();

Activity wf = new Sequence
    Variables = { name },
    Activities =
         new WriteLine
             Text = "What is your name?"
         new ReadLine
             BookmarkName = "UserName",
             Result = new OutArgument<string>(name)

         new WriteLine
             Text = new InArgument<string>((env) => 
                 ("Hello, " + name.Get(env)))

// Create a WorkflowApplication instance.
WorkflowApplication wfApp = new WorkflowApplication(wf);

// Workflow lifecycle events omitted except idle.
AutoResetEvent idleEvent = new AutoResetEvent(false);

wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
    // You can also inspect the bookmarks from the Idle handler
    // using e.Bookmarks


// Run the workflow.

// Wait for the workflow to go idle and give it a chance
// to create the Bookmark.

// Inspect the bookmarks
foreach (BookmarkInfo info in wfApp.GetBookmarks())
    Console.WriteLine("BookmarkName: {0} - OwnerDisplayName: {1}",
        info.BookmarkName, info.OwnerDisplayName);

// Gather the user's input and resume the bookmark.
wfApp.ResumeBookmark("UserName", Console.ReadLine());

.NET Framework
Available since 4.0
Return to top