WorkflowApplication.GetBookmarks 方法

定义

返回工作流实例的书签的集合。Returns the collection of bookmarks for the workflow instance.

重载

GetBookmarks()

返回工作流实例的书签的集合。Returns the collection of bookmarks for the workflow instance.

GetBookmarks(TimeSpan)

使用指定的超时间隔返回工作流实例的书签的集合。Returns the collection of bookmarks for the workflow instance using the specified time-out interval.

GetBookmarks()

返回工作流实例的书签的集合。Returns the collection of bookmarks for the workflow instance.

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::Activities::Hosting::BookmarkInfo ^> ^ GetBookmarks();
public System.Collections.ObjectModel.ReadOnlyCollection<System.Activities.Hosting.BookmarkInfo> GetBookmarks ();
member this.GetBookmarks : unit -> System.Collections.ObjectModel.ReadOnlyCollection<System.Activities.Hosting.BookmarkInfo>
Public Function GetBookmarks () As ReadOnlyCollection(Of BookmarkInfo)

返回

ReadOnlyCollection<BookmarkInfo>

工作流实例的书签的只读集合。A read-only collection of bookmarks for the workflow instance.

示例

下面的示例创建一个使用 ReadLine 活动的工作流,该活动创建一个 BookmarkThe following example creates a workflow that uses a ReadLine activity that creates a Bookmark. 该示例启动工作流,一旦创建了 Bookmark 并且工作流进入空闲状态,就调用 GetBookmarksThe workflow is started, and once the Bookmark is created and the workflow goes idle, GetBookmarks is called. 完成工作流时,会向控制台显示以下输出。When the workflow is completed, the following output is displayed to the console.

What is your name?   
BookmarkName: UserName - OwnerDisplayName: ReadLine  
Steve  
Hello, Steve  
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);
    }
Variable<string> name = new Variable<string>();

Activity wf = new Sequence
{
    Variables = { name },
    Activities =
     {
         new WriteLine
         {
             Text = "What is your name?"
         },
         new ReadLine
         {
             BookmarkName = "UserName",
             Result = new OutArgument<string>(name)
         },
         new WriteLine
         {
             Text = new InArgument<string>((env) =>
                 ("Hello, " + name.Get(env)))
         }
     }
};

// Create a WorkflowApplication instance.
WorkflowApplication wfApp = new WorkflowApplication(wf);

// Workflow lifecycle events omitted except idle.
AutoResetEvent idleEvent = new AutoResetEvent(false);

wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
    // You can also inspect the bookmarks from the Idle handler
    // using e.Bookmarks

    idleEvent.Set();
};

// Run the workflow.
wfApp.Run();

// Wait for the workflow to go idle and give it a chance
// to create the Bookmark.
idleEvent.WaitOne();

// Inspect the bookmarks
foreach (BookmarkInfo info in wfApp.GetBookmarks())
{
    Console.WriteLine("BookmarkName: {0} - OwnerDisplayName: {1}",
        info.BookmarkName, info.OwnerDisplayName);
}

// Gather the user's input and resume the bookmark.
wfApp.ResumeBookmark("UserName", Console.ReadLine());

注解

如果此操作未在 30 秒内完成,则将引发 TimeoutExceptionIf this operation does not complete within 30 seconds, a TimeoutException is thrown.

GetBookmarks(TimeSpan)

使用指定的超时间隔返回工作流实例的书签的集合。Returns the collection of bookmarks for the workflow instance using the specified time-out interval.

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::Activities::Hosting::BookmarkInfo ^> ^ GetBookmarks(TimeSpan timeout);
public System.Collections.ObjectModel.ReadOnlyCollection<System.Activities.Hosting.BookmarkInfo> GetBookmarks (TimeSpan timeout);
member this.GetBookmarks : TimeSpan -> System.Collections.ObjectModel.ReadOnlyCollection<System.Activities.Hosting.BookmarkInfo>
Public Function GetBookmarks (timeout As TimeSpan) As ReadOnlyCollection(Of BookmarkInfo)

参数

timeout
TimeSpan

必须在此时间内完成此方法的时间间隔,否则,将取消该操作并引发 TimeoutExceptionThe interval in which this method must complete before the operation is canceled and a TimeoutException is thrown.

返回

ReadOnlyCollection<BookmarkInfo>

工作流实例的书签的只读集合。A read-only collection of bookmarks for the workflow instance.

示例

下面的示例创建一个使用 ReadLine 活动的工作流,该活动创建一个 BookmarkThe following example creates a workflow that uses a ReadLine activity that creates a Bookmark. 该示例启动工作流,一旦创建了 Bookmark 并且工作流进入空闲状态,就调用 GetBookmarksThe workflow is started, and once the Bookmark is created and the workflow goes idle, GetBookmarks is called. 完成工作流时,会向控制台显示以下输出。When the workflow is completed, the following output is displayed to the console.

What is your name?   
BookmarkName: UserName - OwnerDisplayName: ReadLine  
Steve  
Hello, Steve  
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);
    }
Variable<string> name = new Variable<string>();

Activity wf = new Sequence
{
    Variables = { name },
    Activities =
     {
         new WriteLine
         {
             Text = "What is your name?"
         },
         new ReadLine
         {
             BookmarkName = "UserName",
             Result = new OutArgument<string>(name)
         },
         new WriteLine
         {
             Text = new InArgument<string>((env) =>
                 ("Hello, " + name.Get(env)))
         }
     }
};

// Create a WorkflowApplication instance.
WorkflowApplication wfApp = new WorkflowApplication(wf);

// Workflow lifecycle events omitted except idle.
AutoResetEvent idleEvent = new AutoResetEvent(false);

wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
    // You can also inspect the bookmarks from the Idle handler
    // using e.Bookmarks

    idleEvent.Set();
};

// Run the workflow.
wfApp.Run();

// Wait for the workflow to go idle and give it a chance
// to create the Bookmark.
idleEvent.WaitOne();

// Inspect the bookmarks
foreach (BookmarkInfo info in wfApp.GetBookmarks())
{
    Console.WriteLine("BookmarkName: {0} - OwnerDisplayName: {1}",
        info.BookmarkName, info.OwnerDisplayName);
}

// Gather the user's input and resume the bookmark.
wfApp.ResumeBookmark("UserName", Console.ReadLine());

适用于