Bookmark 类


表示工作流或活动可以被动等待恢复的点。Represents a point at which a workflow or activity can passively wait to be resumed.

public ref class Bookmark : IEquatable<System::Activities::Bookmark ^>
public class Bookmark : IEquatable<System.Activities.Bookmark>
type Bookmark = class
    interface IEquatable<Bookmark>
Public Class Bookmark
Implements IEquatable(Of Bookmark)


下面的示例创建了一个 ReadLine 活动。In the following example, a ReadLine activity is created. 执行时,ReadLine 活动创建 Bookmark,注册回调,然后等待 Bookmark 继续。When executed, the ReadLine activity creates a Bookmark, registers a callback, and then waits for the Bookmark to be resumed. 继续后,ReadLine 活动将随 Bookmark 传递的数据赋给其 Result 实参。When it is resumed, the ReadLine activity assigns the data that was passed with the Bookmark to its Result argument.

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

在下面的示例中,创建了一个工作流,该工作流使用 ReadLine 活动来收集用户的名称并将其显示在控制台窗口中。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. 宿主应用程序将执行收集输入的实际工作并通过继续 Bookmark 将输入传递给该工作流。The host application performs the actual work of gathering the input and passes it to the workflow by resuming the Bookmark.

Variable<string> name = new Variable<string>  
    Name = "name"  

Activity wf = new Sequence  
    Variables =  
    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.  

// Start the workflow.  

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

执行 ReadLine 活动时,该活动创建一个名为 BookmarkUserName,然后等待书签继续。When the ReadLine activity is executed, it creates a Bookmark named UserName and then waits for the bookmark to be resumed. 宿主收集所需的数据,然后继续 BookmarkThe 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. Bookmark 只能在工作流空闲时继续,如果工作流不空闲,则会调用 ResumeBookmark 块,直到工作流空闲。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.


当一个活动创建 Bookmark 时,该活动将进入空闲状态,并等待 Bookmark 继续。When an activity creates a Bookmark, it becomes idle and waits for the Bookmark to be resumed. 如果存在与创建 Bookmark 的活动并行执行的其他活动,则将安排执行这些活动。If there are other activities in parallel with the activity that created the Bookmark, they will be scheduled for execution.

主机应用程序可以使用其中一个 ResumeBookmark 重载继续书签。Bookmarks can be resumed by the host application using one of the ResumeBookmark overloads.

有关书签的详细信息,请参阅使用 WorkflowInvoker 和 WorkflowApplication书签书签 [ Wf 示例]等待输入活动 [wf 示例]示例。For more information about bookmarks, see Using WorkflowInvoker and WorkflowApplication, Bookmarks, and the Bookmarks [ WF Samples] and Wait For Input Activity [WF Samples] samples.



使用指定的名称初始化 Bookmark 类的新实例。Initializes a new instance of the Bookmark class using the specified name.



获取书签名。Gets the bookmark name.



确定当前 Bookmark 和指定的 Bookmark 是否引用工作流中的同一延续点。Determines whether the current Bookmark and the specified Bookmark refer to the same continuation point in a workflow.


确定当前 Bookmark 和指定的对象是否引用工作流中的同一延续点。Determines whether the current Bookmark and the specified object refer to the same continuation point in a workflow.


返回此 Bookmark 实例的唯一标识符。Returns a unique identifier for this Bookmark instance.


获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回已命名书签的书签名,或返回未命名书签的书签 ID。Returns the bookmark name for a named bookmark or the bookmark ID for an unnamed bookmark.