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。
建構函式
| 名稱 | Description |
|---|---|
| Bookmark(String) |
使用指定名稱初始化該類別的新實例 Bookmark 。 |
屬性
| 名稱 | Description |
|---|---|
| Name |
書籤名稱。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Bookmark) | |
| Equals(Object) |
判斷目前 Bookmark 與指定物件是否指向工作流程中的相同續點。 |
| GetHashCode() |
回傳此 Bookmark 實例的唯一識別碼。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
會回傳命名書籤名稱,或回傳未命名書籤的書籤 ID。 |