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、註冊回呼,然後等候繼續 BookmarkWhen 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 時,會變成閒置並等候繼續 BookmarkWhen 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.