I am attempting to write a printed form in F# using WPF controls—-and do so in an asynchronous workflow. Being new to this, I can’t figure out how to place the wpf controls, consumed by the F# asynchronous block, on a STA thread, without blocking the main thread.
I have a lot of printed forms and do not want to block the main thread.
How is a STA thread created for the F# asynchronous workflow?
Thanks in advance for any help.
In pure WPF I don't think you have STA - that concept comes from the COM model. What you do have is a specific UI thread that must be used for communicating with the UI. To get that thread you can use
SynchronizationContext.Currentproperty when you are certain you are on the UI thread (e.g. in an event handler). Note: IfSynchronizationContext.Currentisnullthen you will be running in the thread pool rather than on the UI thread.If you then pass that
SynchronizationContextobject into yourasync {}code, you should be able to rejoin the UI thread by callingAsync.SwitchToContext