1 / 27

WF4 from the Inside Out

FT04. WF4 from the Inside Out. Bob Schmidt Program Manager Microsoft Corporation. What is this talk about?. Discuss the central ideas of WF, show how WF works, get you to experiment Focus is on runtime (what happens) more than programming model (how you express what you want to happen)

jaden
Download Presentation

WF4 from the Inside Out

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FT04 WF4 from the Inside Out Bob Schmidt Program Manager Microsoft Corporation

  2. What is this talk about? • Discuss the central ideas of WF, show how WF works, get you to experiment • Focus is on runtime (what happens) more than programming model (how you express what you want to happen) • You won’t find feature lists, best practices, guidance • You might find ideas, inspiration, insights

  3. Where are we? Visual Studio IIS Management Activities PowerShell Application Host WF Runtime WCF Runtime Persistence Monitoring Storage Process Host

  4. Ideas Programs are data (opacity begone) Scheduler-based program execution (stackless & serializable) Runtime-mediated code rendezvous (thou shalt not block the thread) Natural control flow (run it the way you picture it)

  5. WF Programs demo

  6. Authoring • A WF program is an activity • Can author programmatically or using XAML – or in any format from which an activity can be created • An activity can contain other activities • An activity can have input and output arguments(and also variables) • Separate base classes for activities that return a value • e.g. CodeActivity<TResult>, NativeActivity<TResult> • A WF program is a definition from which many instances can be created • Each instance of an activity has a unique environment(visible data values: args, vars) • InArgument value is obtained from environment

  7. Execution • WF runtime just sees activities, activities, activities (not Sequence, Parallel, Recurrence) • WF runtime is the referee, enforces “rules of the game” • CacheMetadata is how an activity describes itself • WF runtime knows when an activity is done • An activity can schedule the execution of a child activity and be notified upon its completion • There can be multiple, distinct method invocations (“pulses of work”) per activity • Can express all kinds of patterns (control flow) • Multiple paths of execution…

  8. Scheduler External Code Work items are executed one at a time within a single workflow instance Activity Code ADD WF Runtime while !EmptyList Execute(next WorkItem) while !EmptyList Execute(next WorkItem) DoBookkeeping() while !EmptyList Execute(next WorkItem)DoBookkeeping() PUSH Some work items are added to the front of the list, others to the back POP WorkItem 1 WorkItem 2 WorkItem 3 WorkItem 4 ENQUEUE

  9. [ scheduler example ] PARALLEL SEQUENCE1 SEQUENCE2 “1” “3” “2” “4” ■ Parallel.Execute Sequence1.Execute Write(“1”).Execute Write(“2”).Execute Sequence1.Continue Parallel.Continue Write(“4”).Execute Sequence2.Execute Write(“3”).Execute Sequence2.Continue Sequence2.Continue Parallel.Continue Sequence1.Continue Workflow Instance Complete! Sequence2.Execute

  10. Scheduler Details • Scheduler per program instance • Manages an ordered list of work items • Work items can be added by activity code and also by host & external code • Some work items are added at the front, other work items at the back • Executes work items one at a time • The executing work item is never pre-empted • Things can happen between work itemse.g. tracking, persistence

  11. Threading Model • One thread at a time is used to process work items for a program instance • Simplifies the programming model for activities • Thread may differ for work items in the same instance • WF runtime uses host-provided SynchronizationContext • See System.Threading.SynchronizationContext • Extensibility point for host thread management • Standard TLS mechanisms do not apply to WF • Instead: WF Execution Properties - named properties visible for a part (sub-tree) of a workflow • Attached to / detached from the current environment by the WF runtime before / after work item invocation • Activities should not block this thread • WF programs coordinate work

  12. Asynchronous Activities demo

  13. Asynchronous Activities WF Runtime Async Activity I/O code BeginExecute BeginWrite WorkItem AsyncWorkCompletionCallback WorkItem WorkItem WorkItem EndExecute EndWrite WorkItem

  14. Parallel + async activities = true concurrency Parallel p = new Parallel { Branches = { new WriteToFile { FileName = "a", Bytes = … }, new WriteToFile { FileName = "b", Bytes = … } } }; WorkflowInvoker.Invoke(p);

  15. Bookmarks • What happens when your programs need to wait (and wait, and wait) for input? • Maybe there are 1000s of instances waiting • Want a “zero footprint” WaitForInput() • This is a WF bookmark! • A named resumption point in a WF program • Resumption will schedule an activity’s callback method • WF runtime mediates resumption – no need for the instance to be in memory • WCF Receive activity is built on top

  16. Bookmark Resumption “Please deliver [data] to instance [id] at bookmark [name]” External Code Activity Code RESUME WF Runtime CREATE ENQUEUE Work item 1 “pizza” Work item 2 Work item 3 Work item 4

  17. Input Activity demo

  18. Persistence • Persistence lets you pause an instance, save it somewhere & resume it later • A persisted instance has no affinity to a WF host instance, CLR instance, thread, process, or machine • Helps with scalability; helps with recovery from failure • WF program instances are serializable • A CLR stack is not serializable, but in a WF program a stack only exists transiently, during work item execution • Sometimes you want a “no persist zone” • Automatic during execution of an async activity • Details of persistence are deliberately separate from the machinery of the WF runtime

  19. What’s in a Serialized Instance? • A serialized instance contains: • Work item list (empty if instance is idle) • Bookmarks • Data (arg and var values) • Environments for all executing activity instances • Activity instance info (callbacks, execution props) • Custom data from persistence participants • Does not contain the workflow definition • A million instances can share the same definition • Management of definitions is a host responsibility

  20. [ example: a serialized instance ] PARALLEL private int index private int index string s DateTime dint n ■

  21. [ example: a serialized instance ] PARALLEL private int index private int index 3 string s DateTime dint n “hello” INPUT Bookmark:“x” ■

  22. Conclusions • WF is a way of building programs • Use the right control flow & vocabularyfor your situation • Achieve true concurrency where desired • Model arbitrary wait points using bookmarks • Utilize persistence as needed • Highly flexible & extensible • Authoring formats • Custom activities, control flow • Thread management, persistence, hosting

  23. Resources • Ask the Experts tonight • Thursday Sessions • FT13: What's New in WCF 4 • FT14: Workflow Services and Windows Server AppFabric • FT27: Application Server Extensibility with .NET 4and Windows Server AppFabric • http://blogs.msdn.com/endpoint/ bobsch@microsoft.com

  24. YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation forms online at MicrosoftPDC.com

  25. Learn More On Channel 9 • Expand your PDC experience through Channel 9 • Explore videos, hands-on labs, sample code and demos through the new Channel 9 training courses channel9.msdn.com/learn Built by Developers for Developers….

More Related