Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
GetBookmarks Method (TimeSpan)
Collapse the table of content
Expand the table of content

WorkflowApplication.GetBookmarks Method (TimeSpan)

.NET Framework 4.6 and 4.5

Returns the collection of bookmarks for the workflow instance using the specified time-out interval.

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

public ReadOnlyCollection<BookmarkInfo> GetBookmarks(
	TimeSpan timeout
)

Parameters

timeout
Type: System.TimeSpan

The interval in which this method must complete before the operation is canceled and a TimeoutException is thrown.

Return Value

Type: System.Collections.ObjectModel.ReadOnlyCollection<BookmarkInfo>
A read-only collection of bookmarks for the workflow instance.

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: ReadLine
Steve
Hello, Steve
public sealed class ReadLine : NativeActivity<string>
{
    [RequiredArgument]
    public InArgument<string> BookmarkName { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
        // Create a Bookmark and wait for it to be resumed.
        context.CreateBookmark(BookmarkName.Get(context),
            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

    idleEvent.Set();
};

// Run the workflow.
wfApp.Run();

// Wait for the workflow to go idle and give it a chance 
// to create the Bookmark.
idleEvent.WaitOne();

// 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

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4
Show:
© 2015 Microsoft