Bookmark 类

定义

表示工作流或活动可以被动等待恢复的点。

public ref class Bookmark : IEquatable<System::Activities::Bookmark ^>
[System.Runtime.Serialization.DataContract]
public class Bookmark : IEquatable<System.Activities.Bookmark>
[<System.Runtime.Serialization.DataContract>]
type Bookmark = class
    interface IEquatable<Bookmark>
Public Class Bookmark
Implements IEquatable(Of Bookmark)
继承
Bookmark
属性
实现

示例

在以下示例中,创建了一个 ReadLine 活动。 执行时,ReadLine 活动创建 Bookmark,注册回调,然后等待 Bookmark 继续。 恢复时,ReadLine活动会将通过Bookmark传递的数据分配给其Result参数。

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

在以下示例中,创建了一个工作流,该 ReadLine 工作流使用活动收集用户名并将其显示在控制台窗口中。 主机应用程序执行收集输入的实际工作,并通过恢复 Bookmark 将其传递给工作流。

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();

执行 ReadLine 活动时,该活动创建一个名为 BookmarkUserName,然后等待书签继续。 宿主收集所需的数据,然后继续 Bookmark。 工作流恢复后,会显示名称,然后完成。 请注意,恢复书签时不需要同步代码。 Bookmark只能在工作流空闲时恢复,如果工作流不空闲,对ResumeBookmark的调用会阻塞,直到工作流变为空闲。

注解

活动创建一个 Bookmark时,它将变为空闲状态,并等待 Bookmark 恢复。 如果其他活动与创建活动 Bookmark并行,则会计划执行这些活动。

主机应用程序可以使用其中一个 ResumeBookmark 重载恢复书签。

有关书签的详细信息,请参阅 使用 WorkflowInvoker 和 WorkflowApplicationBookmarks

构造函数

名称 说明
Bookmark(String)

使用指定的名称初始化类的新实例 Bookmark

属性

名称 说明
Name

获取书签名称。

方法

名称 说明
Equals(Bookmark)

确定当前 Bookmark 和指定的 Bookmark 引用工作流中的同一延续点。

Equals(Object)

确定当前 Bookmark 对象和指定的对象是否引用工作流中的同一延续点。

GetHashCode()

返回此 Bookmark 实例的唯一标识符。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回已命名书签的书签名称或未命名书签的书签 ID。

适用于