Bookmark 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示工作流或活动可以被动等待恢复的点。
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 活动时,该活动创建一个名为 Bookmark 的 UserName,然后等待书签继续。 宿主收集所需的数据,然后继续 Bookmark。 工作流继续,显示该名称,然后完成。 请注意,不需要与继续书签有关的任何同步代码。 
              Bookmark 只能在工作流空闲时继续,如果工作流不空闲,则会调用 ResumeBookmark 块,直到工作流空闲。
注解
当一个活动创建 Bookmark 时,该活动将进入空闲状态,并等待 Bookmark 继续。 如果存在与创建 Bookmark 的活动并行执行的其他活动,则将安排执行这些活动。
主机应用程序可以使用其中一个 ResumeBookmark 重载继续书签。
有关书签的详细信息,请参阅 使用 WorkflowInvoker 和 WorkflowApplication and Bookmarks。
构造函数
| Bookmark(String) | 使用指定的名称初始化 Bookmark 类的新实例。 | 
属性
| Name | 获取书签名。 | 
方法
| Equals(Bookmark) | |
| Equals(Object) | 确定当前 Bookmark 和指定的对象是否引用工作流中的同一延续点。 | 
| GetHashCode() | 返回此 Bookmark 实例的唯一标识符。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回已命名书签的书签名,或返回未命名书签的书签 ID。 |