STATHREAD as an asynchronous workflow in F #

Consider the following code snippet:

let t1 = async {return process1 ()}
let t2 = async {return process2 ()}
let t3 = async {return windowsProcess ()}

let execute =
    [t1; t2; t3]
    |> Async.Parallel
    |> Async.RunSynchronously
    |> ignore

What to do if WindowsProcess requires STATHREAD? Is this possible with this design?

+2
source share
1 answer

If there is a specific thread with SyncrhonizationContext, for example. UI thread, then you could do, for example.

// earlier on the UI thread...
let syncCtxt = System.Threading.SynchronizationContext.Current 

// then define t3 as
let t3 = async { 
    do! Async.SwitchToGuiThread(syncCtxt)
    // now we're running on the UI thread until the next async 'bind' point
    return windowsProcess() 
    }

but in general, concurrent tasks will start in threadpool.

+5
source

Source: https://habr.com/ru/post/1695737/


All Articles