Dealing with multiple bookmarks in windows workflow 4.5

274 Views Asked by At

I am just starting with windows workflow 4.5. I am creating a simple console app. I am asking the user for data along the way. I followed some tutorials and I created some activities which ask the user for different data. Those Activities create bookMarks. How do I handle these multiple bookmarks in my host program. The tutorial had a loop and seemed to assumed that there would only be one bookmark. which looks like

    WaitHandle[] handles = new WaitHandle[] { syncEvent, idleEvent };
    while (WaitHandle.WaitAny(handles) != 0)
    {
        bool needsReview = false;
        while (!needsReview)
        {
            var response = Console.ReadLine();
            Boolean review;
            if (response == "y")
            {
                needsReview = true;
                review = true;
                wfApp.ResumeBookmark("Review", review);
            }
            else if (response == "n")
            {
                needsReview = true;
                review = false;
                wfApp.ResumeBookmark("Review", review);
            }
            else
            {
                Console.WriteLine("Enter 'y' or 'n'");
            }
        }
    }

How do I properly write this when I am dealing with many prompts to the user that have to handle information in different ways and resume different bookmarks.

2

There are 2 best solutions below

0
A Khudairy On

If you are developing a console application, then it is a desktop application. So I assume there is one user, and one workflow working at a time. Is it possible that the workflow is stopped at different bookmarks? Am not sure what you mean in real life.

On any ways the bookmark name is a way to identify the different bookmarks, and you can also keep the bookmark object when you create one

Bookmark bookmark = wfApp.CreateBookmark("aasdasd");
0
Greg May On

I think I have the answer to this. There is a GetBookmarks property in the WorkflowApplication object. In my simple Activity which has two bookmarks, GetBookmarks only contains the single bookmark which I need each time the Activity pauses.

Given it is a Collection (a ReadonlyCollection(Of Hosting.BookmarkInfo) to be precise), there may be circumstances where it does contain more than one item, guessing something like parallel branches.

Either way, you can do an if-then-else or switch to interrogate this and return all correct info.

For example:

Hosting.BookmarkInfo ThisBookmark = CurrentBookmarks.First;

string InputName = Console.ReadLine;

wfApp.ResumeBookmark(ThisBookmark.BookmarkName, InputName);

Obviously adjusting the above for input types etc.