views:

212

answers:

1

I'm looking hard at WF 4.0 right now, but I'm having a hard time figuring out how to run workflows in STA threads. I've got a requirement for constructing XPS documents in a workflow, which means I need to create UI elements (FixedPage), which means the thread running the workflow has to be STA.

In 3.0, you could do some magic (I didn't manage this part of the code, so no details here) with the ManualWorkflowSchedulerService to get the workflow running in a STA thread. But now 4.0 is much different; even beta 2 is different from beta 1...

Anybody know how to get 4.0 workflows running in STA threads?


I can't use the WorkflowInvoker because it is only for short-lived workflows that don't require persistence, which I do.

+2  A: 

Have you tried using the WorkflowInvoker? This should just execute the workflow on the original thread and not schedule work on a background tread.

Maurice
I just saw that. But it also blocks the current thread, which isn't optimal...
Will
When you are using the WorkflowApplication you can set the SynchronizationContext and gain control over the threads. By default, if the SynchronizationContext isn't set, it will use the ThreadPool completion ports. But if you set the WorkflowApplication.SynchronizationContext to SynchronizationContext.Current in say WPF your activities will execute on the UI thread instead of the ThreadPool. The contents of SynchronizationContext.Current are dependend on the execution environment or you can create your own implementation if need be.
Maurice
I'll look into that. I checked it out before and didn't see anything relating to creating threads or scheduling jobs...
Will
Yep, its the SynchronizationContext.
Will