STATHREAD作为F#中的异步工作流

编程入门 行业动态 更新时间:2024-10-09 18:18:33
本文介绍了STATHREAD作为F#中的异步工作流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

考虑以下代码片段:

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

在windowsProcess需要STATHREAD的情况下该怎么办?这种构造有可能吗?

What to do in the case the windowsProcess requires a STATHREAD? Is this possible with this construction?

推荐答案

如果存在带有SyncrhonizationContext的特定线程,例如UI线程,那么您可以执行例如

If there's a particular thread with a SyncrhonizationContext, e.g. the UI thread, then you could do e.g.

// 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 parallel tasks will start in the threadpool.

更多推荐

STATHREAD作为F#中的异步工作流

本文发布于:2023-11-23 23:14:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623133.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作流   STATHREAD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!