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。

適用於