WorkflowApplication.GetBookmarks Метод

Определение

Возвращает коллекцию закладок для экземпляра рабочего процесса.

Перегрузки

GetBookmarks()

Возвращает коллекцию закладок для экземпляра рабочего процесса.

GetBookmarks(TimeSpan)

Возвращает коллекцию закладок для экземпляра рабочего процесса, используя указанный интервал времени ожидания.

GetBookmarks()

Возвращает коллекцию закладок для экземпляра рабочего процесса.

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)

Возвращаемое значение

Доступная только для чтения коллекция закладок для экземпляра рабочего процесса.

Примеры

В следующем примере создается рабочий процесс, который использует действие ReadLine, создающее Bookmark. Рабочий процесс запускается, и, когда создается Bookmark, а рабочий процесс переходит в состояние бездействия, вызывается метод GetBookmarks. После завершения рабочего процесса на консоль выводятся следующие данные.

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 секунд, то вызывается исключение TimeoutException.

Применяется к

GetBookmarks(TimeSpan)

Возвращает коллекцию закладок для экземпляра рабочего процесса, используя указанный интервал времени ожидания.

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

Интервал, в течение которого этот метод должен завершить работу до отмены операции и создания исключения TimeoutException.

Возвращаемое значение

Доступная только для чтения коллекция закладок для экземпляра рабочего процесса.

Примеры

В следующем примере создается рабочий процесс, который использует действие ReadLine, создающее Bookmark. Рабочий процесс запускается, и, когда создается Bookmark, а рабочий процесс переходит в состояние бездействия, вызывается метод GetBookmarks. После завершения рабочего процесса на консоль выводятся следующие данные.

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());

Применяется к