Home > .NET Framework, workflow > ProWF 4: Chapter 8 errata

ProWF 4: Chapter 8 errata

A problem with the code for one of the examples has just been brought to my attention. The code for the ProblemReporting example in Chapter 8 is missing several lines.  This code can be found on page 309 of the first edition of the book.  The missing lines synchronize the code that is assigned to the Notification event with the Idle event of the workflow instance.  Without this code, the code assigned to the Notification event may execute before the workflow is idle and before the bookmarks have been created.

Here is the revised section of code for the Program.cs file of the ProblemReporting project.  The lines that should be added are highlighted below:

static void Main(string[] args)
        AutoResetEvent syncEvent = new AutoResetEvent(false);
        AutoResetEvent idleEvent = new AutoResetEvent(false);

        WorkflowApplication wfApp =
            new WorkflowApplication(new ProblemReporting());

        wfApp.Completed = delegate(
            WorkflowApplicationCompletedEventArgs e)

        wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
            idleEvent.Set(); //signal that the workflow is idle
            Console.WriteLine("Workflow is idle");

        wfApp.OnUnhandledException = delegate(
            WorkflowApplicationUnhandledExceptionEventArgs e)
            return UnhandledExceptionAction.Terminate;

        HostEventNotifier extension = new HostEventNotifier();
        extension.Notification += delegate(
            Object sender, HostNotifyEventArgs e)

            idleEvent.WaitOne(2000); //wait until the workflow is idle

            var bookmarks = wfApp.GetBookmarks();
            if (bookmarks != null && bookmarks.Count > 0)
                Console.WriteLine("Select one of these available actions:");
                foreach (BookmarkInfo bookmark in bookmarks)
                    Console.WriteLine("->{0}", bookmark.BookmarkName);

            Boolean isWaitingForChoice = true;
            while (isWaitingForChoice)
                String newAction = Console.ReadLine();
                if (IsBookmarkValid(wfApp, newAction))
                    isWaitingForChoice = false;
                    wfApp.ResumeBookmark(newAction, null);
                    Console.WriteLine("Incorrect choice!");

    catch (Exception exception)
        Console.WriteLine("Error: {0}", exception.Message);
Categories: .NET Framework, workflow Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: