views:

101

answers:

1

Hi.

We have issues within an application using a state machine. The application is implemented as a windows service and is iteration based (it "foreaches" itself through everything) and there are myriads of instances being processed by the state machine.

As I'm reading the MEAP version of Jon Skeets book "C# in Depth, 2nd ed", I'm wondering if I can change the whole thing to use linq expression instances so that guards and conditions are represented using expression trees.

We are building many applications on this state machine engine and would probably greatly benefit from the new Expression tree visualizer in VS 2010

Now, simple example. If I have an expression tree where there is an OR Expression condition with two sub nodes, is there any way that these can implement the observer pattern so that the expression tree becomes event driven? If a condition change, it should notify its parent node (the OR node). Since the OR node then changes from "false" to "true", then it should notify ITS parent and so on.

I love the declarative model of expression trees, but the deferred execution model works in opposite direction of the control flow if you want event based "live" conditions.

Am I off on a wild goose chase here? Or is there some concept in the BCL that may help me achieve this?

+5  A: 

It sounds like the new Reactive Framework may be of interest to you:

Rx is a library for composing asynchronous and event-based programs using observable collections.

Andrew Hare
See one of the last sections of chapter 12 of the MEAP for a brief introduction to Reactive Extensions :)
Jon Skeet
Priceless. As you've probably guessed I'm not done reading the book. And, lo and behold, chapter 12.5 : "Inverting the query model with LINQ to Rx".
Tormod
And finally I get to do some of the reading on company time.... ;) And, by the way, great book!
Tormod
@Tormod: Glad you're enjoying it :) Obviously (as you've no doubt discovered now) I only skim the surface of Rx - it's more to show the flexibility of LINQ than to explore Rx itself.
Jon Skeet