Bookmark Class (System.Activities)

Switch View :
ScriptFree
.NET Framework Class Library
Bookmark Class

Represents a point at which a workflow or activity can passively wait to be resumed.

Inheritance Hierarchy

System.Object
  System.Activities.Bookmark

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

Visual Basic
<DataContractAttribute> _
Public Class Bookmark _
	Implements IEquatable(Of Bookmark)
C#
[DataContractAttribute]
public class Bookmark : IEquatable<Bookmark>
Visual C++
[DataContractAttribute]
public ref class Bookmark : IEquatable<Bookmark^>
F#
[<DataContractAttribute>]
type Bookmark =  
    class
        interface IEquatable<Bookmark>
    end

The Bookmark type exposes the following members.

Constructors

  Name Description
Public method Bookmark Initializes a new instance of the Bookmark class using the specified name.
Top
Properties

  Name Description
Public property Name Gets the bookmark name.
Top
Methods

  Name Description
Public method Equals(Bookmark) Determines whether the current Bookmark and the specified Bookmark refer to the same continuation point in a workflow.
Public method Equals(Object) Determines whether the current Bookmark and the specified object refer to the same continuation point in a workflow. (Overrides Object.Equals(Object).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Returns a unique identifier for this Bookmark instance. (Overrides Object.GetHashCode().)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns the bookmark name for a named bookmark or the bookmark ID for an unnamed bookmark. (Overrides Object.ToString().)
Top
Remarks

When an activity creates a Bookmark, it becomes idle and waits for the Bookmark to be resumed. If there are other activities in parallel with the activity that created the Bookmark, they will be scheduled for execution.

Bookmarks can be resumed by the host application using one of the ResumeBookmark overloads.

For more information about bookmarks, see Using WorkflowInvoker and WorkflowApplication, Bookmarks, and the Bookmarks and Wait For Input Activity samples.

Examples

In the following example, a ReadLine activity is created. When executed, the ReadLine activity creates a Bookmark, registers a callback, and then waits for the Bookmark to be resumed. When it is resumed, the ReadLine activity assigns the data that was passed with the Bookmark to its Result argument.

C#
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);
    }
}

In the following example, a workflow is created that uses the ReadLine activity to gather the user’s name and display it to the console window. The host application performs the actual work of gathering the input and passes it to the workflow by resuming the Bookmark.

C#
Variable<string> name = new Variable<string>
{
    Name = "name"
};

Activity wf = new Sequence
{
    Variables =
    {
        name
    },
    Activities =
    {
        new WriteLine()
        {
            Text = "What is your name?"
        },
        new ReadLine()
        {
            BookmarkName = "UserName",
            Result = name
        },
        new WriteLine()
        {
            Text = new InArgument<string>((env) => "Hello, " + name.Get(env))
        }
    }
};

AutoResetEvent syncEvent = new AutoResetEvent(false);

// Create the WorkflowApplication using the desired
// workflow definition.
WorkflowApplication wfApp = new WorkflowApplication(wf);

// Handle the desired lifecycle events.
wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
    // Signal the host that the workflow is complete.
    syncEvent.Set();
};

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

// Collect the user's name and resume the bookmark.
// Bookmark resumption only occurs when the workflow
// is idle. If a call to ResumeBookmark is made and the workflow
// is not idle, ResumeBookmark blocks until the workflow becomes
// idle before resuming the bookmark.
wfApp.ResumeBookmark("UserName", Console.ReadLine());

// Wait for Completed to arrive and signal that
// the workflow is complete.
syncEvent.WaitOne();

When the ReadLine activity is executed, it creates a Bookmark named UserName and then waits for the bookmark to be resumed. The host collects the desired data and then resumes the Bookmark. The workflow resumes, displays the name, and then completes. Note that no synchronization code is required with regard to resuming the bookmark. A Bookmark can only be resumed when the workflow is idle, and if the workflow is not idle, the call to ResumeBookmark blocks until the workflow becomes idle.

Version Information

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference