Workflow 4 parallel and compensation activities

So I’m looking into workflow foundation 4 (using Visual Studio 2010 Beta 2). Let’s look at the parallel activity included within. The parallel activity will schedule all of its child activities asynchronously and then wait until all children have completed or the CompletionCondition evaluates to True.

Let’s do a little experiment: Start Visual Studio and create a new workflow console application.

Drag a Sequence activity to the designer. In it add a WriteLine activity and a Parallel activity.

Drag a sequence activity inside the parallel activity. It will automatically split up to allow other branches:

image

Rename this sequence to left, then add a WriteLine activity, a Delay and another WriteLine activity.

Repeat this for the right branch, calling it Right. Now we only need to add two variables to time the delays. Select the Start sequence, and on the bottom of the designer click on the variables button. This will open the variables window:

image

In here define two variables leftDelay and rightDelay and make them of type TimeSpan using the dropdown combobox and select “Browse for Types…”. This should open the “Browse and Select a .NET Type” dialog. One of the new things I like about this window is that you can search for a type:

image

Finally we should end up with this:

image

Run and you should get this:

image

As you can see the parallel activity will now execute both left and right branches. But what if you want one of the branches to stop because another branch has done all that is needed? For that we can use the Parallel’s activity CompletionCondition. When one of the branches of the parallel activity completes, the parallel activity will check its CompletionCondition. If set to false, it will allow other braches to continue. Otherwise it will cancel the other, still running, branches.

So let’s test this. Click on the parallel activity and add a new boolean variable called stopProcessing (I’ve renamed the parallel activity Race, so that’s set as the stopProcessing variable’s scope):

image

Now set the parallel activity CompletionCondition to this variable by clicking the activity and using the property window:

image

Next add to each branch an assignment activity after the last writeline to set the stopProcessing to true:

image

Run: you should see one branch complete while the other never does:

image

And what about doing something when you get cancelled?

To do this we need to use a CancellationScope. A CancellationScope allows you to define what needs to be done when a branch gets cancelled, for example in a parallel activity because another branch completed with the CompletionCondition set to True.

Let’s try this. Inside the parallel activity drag a CancellationScope. Then drag the left branch in it. Repeat with a new CancellationScope for the right branch. Drag a WriteLine activity into each CancellationScope’s CancellationHandler. For example the left side should write “Left was cancelled” in the CancellationHandler:

image

Run again: You should now see one side complete, and the other being cancelled:

image

WARNING: Although you might think it is a good idea to schedule as much work as possible in parallel, this will not make your orchestration faster. WF will still schedule all activities on the same thread, so if your activities never go idle, it will take the same amount of time as if you’re using a sequence. Only if each branch in the parallel activity needs to wait on some response will using the parallel activity make a difference.


Comments (6) -

January 22. 2010 12:01 AM

creative thinking techniques

Admiring the time and effort you put into your blog and detailed information you offer! I will bookmark your blog and have my children check up here often. Thumbs up!

creative thinking techniques

January 22. 2010 09:06 PM

online personal loans

A leader has the vision and conviction that a dream can be achieved. He inspires the power and energy to get it done.

online personal loans

January 23. 2010 11:52 PM

online rulett

When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get four emails with the same comment.
Is there any way you can remove me from that service?
Thanks!

online rulett

January 24. 2010 11:32 PM

NJ Website Design

Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I'm more of a visual learner,I found that to be more helpful well let me know how it turns out! I love what you guys are always up too. Such clever work and reporting! Keep up the great works guys I've added you guys to my blogroll. This is a great article thanks for sharing this informative information.. I will visit your blog regularly for some latest post.

NJ Website Design

January 25. 2010 07:53 AM

Tutor

I was looking for crucial information on this subject. The information was important as I am about to launch my own portal. Thanks for providing a missing link in my business.

Tutor

January 25. 2010 02:08 PM

payday loans

I have learned from experience that the greater part of our happiness or misery depends on our dispositions and not on our circumstances.

payday loans

January 25. 2010 02:08 PM

payday loans

Think of yourself as on the threshold of unparalleled success. A whole clear, glorious life lies before you. Achieve! Achieve!

payday loans

January 26. 2010 01:38 AM

how to whiten teeth

Great post! I am just starting out in community management/marketing media and trying to learn how to do it well - resources like this article are incredibly helpful. As our company is based in the US, it?s all a bit new to us. The example above is something that I worry about as well, how to show your own genuine enthusiasm and share the fact that your product is useful in that case.

how to whiten teeth

January 27. 2010 04:18 AM

how to get lots money

Well, this is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in the same niche. Your blog provided us valuable information to work on. You have done a marvellous job!

how to get lots money

January 29. 2010 10:56 PM

contractor accountant

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.

contractor accountant

January 30. 2010 01:15 AM

IT contractor accountants

I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will find that very useful.

IT contractor accountants

January 31. 2010 04:29 PM

home lighting

The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!

home lighting

February 2. 2010 06:37 AM

billigt bredbånd

Just wanted to give you a shout from the valley of the sun, great information. Much appreciated.

billigt bredbånd

February 4. 2010 05:16 PM

pamper coupons

I was looking for crucial information on this subject. The information was important as I am about to launch my own portal. Thanks for providing a missing link in my business.

pamper coupons

February 5. 2010 11:40 AM

real estate

I was wondering what is up with that weird gravatar??? I know 5am is early and I'm not looking my best at that hour, but I hope I don't look like this! I might however make that face if I'm asked to do 100 pushups. lol

real estate

February 6. 2010 08:36 PM

tie a tie

The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!

tie a tie

February 6. 2010 09:46 PM

mccall idaho home listings

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the bloggin

mccall idaho home listings

February 8. 2010 01:02 PM

restaurant loans

This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article

restaurant loans

February 8. 2010 05:01 PM

affordable health care plans

Hi webmaster, commenters and everybody else !!! The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!b Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do!

affordable health care plans

February 9. 2010 09:12 AM

acai berry review

To solve any problem, here are three questions to ask yourself: First, what could I do? Second, what could I read? And third, who could I ask?

acai berry review

February 9. 2010 09:12 AM

acai health

Let me tell you the secret that has led me to my goal. My strength lies solely in my tenacity.

acai health

February 10. 2010 07:43 AM

post menopausal

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

post menopausal

February 10. 2010 07:49 AM

rheumatoid arthritis joint pain

I completely agree with the above comment, the internet is with a doubt growing into the most important medium of communication across the globe and its due to sites like this that ideas are spreading so quickly.

rheumatoid arthritis joint pain

February 10. 2010 12:06 PM

best hearing aid

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!

best hearing aid

February 13. 2010 05:58 AM

mafia wars cheats

How-do-you-do, just needed you to know I have added your site to my Google bookmarks because of your extraordinary blog layout. But seriously, I think your site has one of the freshest theme I've came across. It really helps make reading your blog a lot easier.

mafia wars cheats

February 13. 2010 10:40 AM

ip security cameras

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It's always nice when you can not only be informed, but also entertained! I'm sure you had fun writing this article.

ip security cameras

February 13. 2010 01:02 PM

Arvada Garage Door Repair

Howdy, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam comments? If so how do you prevent it, any plugin or anything you can advise? I get so much lately it's driving me mad so any assistance is very much appreciated.

Arvada Garage Door Repair

February 13. 2010 11:55 PM

Plainfield Garage Door Repair

That is some inspirational stuff. Never knew that opinions could be this varied. Thanks for all the enthusiasm to offer such helpful information here.

Plainfield Garage Door Repair

February 14. 2010 12:59 AM

New York Brooklyn Garage Door Repair

Hi. I wanted to drop you a quick note to express my thanks. I've been following your blog for a month or so and have picked up a ton of good information as well as enjoyed the way you've structured your site. I am attempting to run my own blog but I think its too general and I want to focus more on smaller topics. Being all things to all people is not all that its cracked up to be.

New York Brooklyn Garage Door Repair

February 14. 2010 01:01 AM

New York Manhattan Garage Door Repair

I must say that overall I am really impressed with this blog.It is easy to see that you are passionate about your writing. If only I had your writing ability I look forward to more updates and will be returning.

New York Manhattan Garage Door Repair

February 14. 2010 01:53 PM

jawhorse

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.

jawhorse

February 14. 2010 05:54 PM

kitchenaid classic mixer

Couldn?t be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing!

kitchenaid classic mixer

February 15. 2010 04:08 AM

billigt bredbånd

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

billigt bredbånd

February 16. 2010 01:28 PM

contemporary duvet covers

I am not much of a guy who thinks in so deeply about web design but I think your post had some valid points in it. Like designers are forced to design stuff within the limited code available and not go beyond it, their innovation is somewhat limited but still I think Web Design won't die! I agree that Amazon and other some big sites won't have a blog but now a days it's very important to have some sort of option available so people can quickly communicate their thoughts. I think Amazon if wants to shift it to that, they can get a customized CMS for themselves.

contemporary duvet covers

February 24. 2010 04:22 AM

Pop Up Stands

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

Pop Up Stands

February 25. 2010 08:21 PM

round about place

The beauty of these blogging engines and CMS platforms is the lack of limitations and ease of manipulation that allows developers to implement rich content and 'skin' the site in such a way that with very little effort one would never notice what it is ma

round about place

February 28. 2010 01:37 AM

Houston Computer Repair

Great post! I am just starting out in community management/marketing media and trying to learn how to do it well - resources like this article are incredibly helpful. As our company is based in the US, it?s all a bit new to us. The example above is something that I worry about as well, how to show your own genuine enthusiasm and share the fact that your product is useful in that case.

Houston Computer Repair

February 28. 2010 02:52 AM

honeywell electric heater

Uw blog is zeer interessant

honeywell electric heater

March 9. 2010 05:20 AM

Ligia Thorpe

I'm happy I located this weblog, I couldnt obtain any knowledge on this subject before. Also run a niche site and if you wish to ever interested in doing a bit of visitor writing for me you should feel free to let me know, im always look for people to check out my site. Please stop by and leave a comment sometime!

Ligia Thorpe

March 15. 2010 09:46 PM

Jacques Raglin

Good post, this is very similar to a site that I have. Please check it out sometime and feel free to leave me a comenet on it and tell me what you think. Im always looking for feedback.

Jacques Raglin

September 16. 2011 10:13 PM

Instaflex

thank you for sharing this information i am waiting for another
<a href="www.jointhealthmagazine.com/.../a>;

Instaflex

October 17. 2011 03:23 PM

ugg sale uk

thank you for sharing this information i am waiting for another

ugg sale uk

November 30. 2011 06:19 PM

canada goose jacket

compulsory education, with <b><a href="www.echristianlouboutinsale.org/">christian louboutin pumps</a></b> honors admitted Wanyuan school, but failed to come home <b><a href="www.echristianlouboutinsale.org/">louboutin sale</a></b> tuition, the p...  <b><a href="www.echristianlouboutinsale.org/">christian louboutin sale</a></b>

canada goose jacket

December 28. 2011 05:43 PM

Retro Jordan Shoes

<strong><a href=http://www.todsukonline.com/ >tods shoes</a></strong><p> <strong><a href=http://www.todsukonline.com/ title="tods uk">tods uk</a></strong> Economic Observer <strong><a href=http://www.todsukonline.com/ title="tods shoes uk">tods shoes uk</a></strong> Online <strong><a href=http://www.todsukonline.com/ title="tods loafers">tods loafers</a></strong> reporter Yang Yang Beijing <strong><a href=http://www.todsukonline.com/ title="tods shoes">tods shoes</a></strong> on <strong><a href=http://www.todsukonline.com/ >tods shoes</a></strong>October 14 Wall Street Journal reported that America Online (hereinafter referred to as The <strong><a href=http://www.todsukonline.com/ title="tods boots">tods boots</a></strong> news apparently stim...

Retro Jordan Shoes

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Download the U2U brochure

Download Brochure

Receive the U2U Newsletter. Submit your email address:
 
 


 


Search

rss  RSS

Recent posts

None

Archive