The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Workflow 4 and Visual Basic expressions

Note: This blog post is written using the .NET framework 4.0 Beta 2

When using Windows Workflow Foundation 4 you often need to enter expression in some activity property. The new thing is these expressions are all in the Visual Basic dialect regardless of what language you project is in. So when developing a project in C# the expressions are sill in Visual Basic.

Weird right?

Well not really when you think about it!

After all power business users are expected to be able to modify workflows. And guess what their favorite tools are. That would be Microsoft Excel and Word. And what do they use to create macros? Right Visual Basic for Applications is their language of choice.

 

So if they use VBA letting them enter VB into expression dialogs is a far more natural fit than having them use C#.

 

A case for the Delay activity

So lets take a look at the delay activity. This activity takes 1 input property Duration of type Time Span. So I guess that means our VBA power users are going to have to enter something like if they want to wait 5 seconds:

image

Now for some reason I suspect that is not the first thing they are going to type. In fact they are more likely to time something like “0:0:05” instead. Not very VB like right?

Well it turns out workflow is smart enough to realize it can convert the string literal to a Time Span and use this. So when our power users does the following it just works Smile

image

Nice, I like this!

 

Enjoy WF4!

 

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Published Mon, Oct 26 2009 17:20 by Maurice
Filed under: , , , , ,

Comments

# re: Workflow 4 and Visual Basic expressions@ Monday, October 26, 2009 1:02 PM

I saw somewhere that WF team used VB for expressions because the VB team gave them an in-memory parser in time for .NET 4.0 RTM. That's the main reason I think :).

by cibrax

# re: Workflow 4 and Visual Basic expressions@ Monday, October 26, 2009 1:44 PM

@cibrax,

That on not the explanation I was given. And it would be a new experience where CSD reused something from another team. Normally they rebuild/reinvent everything as they believe they can do a far better job.

by Maurice

# Workflow 4 and Visual Basic expressions@ Monday, October 26, 2009 4:50 PM

DotNetBurner - burning hot .net content

# re: Workflow 4 and Visual Basic expressions@ Tuesday, October 27, 2009 7:57 PM

Forcing everyone to use VB because it is more convenient for business people is the stupidest excuse I have ever heard.  What about all the applications that have nothing to do with business?  Being forced to write code in the .net language for amateurs sucks big time.  If you set aside this really irritating issue the workflow team is doing a great job IMHO.

by Robert

# re: Workflow 4 and Visual Basic expressions@ Thursday, October 29, 2009 3:22 PM

It would be better to have an expression interpreter provider that to do the job. So everyone can write the expressions in the language that thay prefer, just changing/adding the provider in config file, just like memberships provider or something else.

by Ernesto

# re: Workflow 4 and Visual Basic expressions@ Thursday, October 29, 2009 4:41 PM

@Ernesto,

I agree, the workflow should just store a parsed version of the expression and you should be able to edit it in whatever dialect works best for you. Unfortunately that isn't the case for now. Lets hope they enable that some time in the future.

by Maurice

# re: Workflow 4 and Visual Basic expressions@ Friday, October 30, 2009 11:45 PM

@Ernesto,

the workflow runtime is agnostic when it comes to expression languages, there are all the extensibility points to add in a parser, even an extension point to add a custom dialog/ visual editor for the expressions.  It is possible to enable the scenario that you mention, where we could have a provider, it is just not something that we enable out of the box, nor do we have a designer that we ship for other languages besides vb (specifically referring to the expression text box).

We're working on a sample that shows how you could implement a different expression text box if you want to support a different language (and also require a parser, etc).

by mwinkle

# re: Workflow 4 and Visual Basic expressions@ Wednesday, November 11, 2009 9:37 AM

Omg, this is probably the worst explanation I can ever imagine. Why MS deals with business users in technology for developers? Have you ever seen any business user who at least understands exception handling, compensation, transactions, persistence, services or event driven execution? How can people without solid knowledge of these key concepts modify WF? How many WF projects target on business users? I guess no more than 20%. But I understand it sounds great on marketing presentations.  

by Ladislav

# re: Workflow 4 and Visual Basic expressions@ Wednesday, November 11, 2009 10:09 AM

@Ladislav,

I know the feeling. However that said there is some benefit to this. Having the workflow runtime to let users add to your app by rehosting the designer is not a bad idea by itself. The question is how practical this is in the real world. It remains to be seen.

And there is nothing wrong with marketing. No really, it means we can get payed to do all the cool stuff we enjoy :-)

by Maurice

# re: Workflow 4 and Visual Basic expressions@ Friday, December 25, 2009 7:16 AM

Why in world VB ? I have been preparing myself for WF 4.0 for some time and now when I finally started to get my hands dirty , I found myself into completely different world.I have never programmed with VB and I have no idea whats the syntax for initializing Dictionary in VB(yes I can look into google for help but that's too much).

Maurice , Just let us know how much of knowledge of VB will be okay to get started with WF.

by Pawan Mishra

# re: Workflow 4 and Visual Basic expressions@ Friday, December 25, 2009 7:29 AM

Hi Pawan,

Don't worry about it. Its only VB expressions not complete functions so the difference isn't that big. For the most case VB has some extra but optional behavior. There are a few thing different like && is "And" and || is "Or" and "\n" isn't seen as a newline.

Maurice

by Maurice

# re: Workflow 4 and Visual Basic expressions@ Friday, January 08, 2010 3:33 AM

I was about to start a WWF project then read this post about having to go back to VB. Match abandoned! What a crazy idea.

by Bob Morris