wf4 from the inside out l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
WF4 from the Inside Out PowerPoint Presentation
Download Presentation
WF4 from the Inside Out

Loading in 2 Seconds...

play fullscreen
1 / 27

WF4 from the Inside Out - PowerPoint PPT Presentation


  • 584 Views
  • Uploaded on

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)

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'WF4 from the Inside Out' - jaden


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
wf4 from the inside out
FT04

WF4 from the Inside Out

Bob Schmidt

Program Manager

Microsoft Corporation

what is this talk about
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
where are we
Where are we?

Visual Studio

IIS Management

Activities

PowerShell

Application Host

WF Runtime

WCF

Runtime

Persistence

Monitoring

Storage

Process Host

ideas
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)

authoring
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
execution
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…
scheduler
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

slide9

[ 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

scheduler details
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
threading model
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
asynchronous activities13
Asynchronous Activities

WF Runtime

Async

Activity

I/O code

BeginExecute

BeginWrite

WorkItem

AsyncWorkCompletionCallback

WorkItem

WorkItem

WorkItem

EndExecute

EndWrite

WorkItem

slide14

Parallel + async activities = true concurrency

Parallel p = new Parallel

{

Branches =

{

new WriteToFile { FileName = "a", Bytes = … },

new WriteToFile { FileName = "b", Bytes = … }

}

};

WorkflowInvoker.Invoke(p);

bookmarks
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
bookmark resumption
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

persistence
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
what s in a serialized instance
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
slide20

[ example: a serialized instance ]

PARALLEL

private int index

private int index

string s

DateTime dint n

slide21

[ example: a serialized instance ]

PARALLEL

private int index

private int index

3

string s

DateTime dint n

“hello”

INPUT

Bookmark:“x”

conclusions
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
resources
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

slide24

YOUR FEEDBACK IS IMPORTANT TO US!

Please fill out session evaluation forms online at

MicrosoftPDC.com

learn more on channel 9
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….