Stathread كما سير عمل ASYNC في F #
-
12-09-2019 - |
سؤال
النظر في جزء التعليمات البرمجية التالية:
دع T1 = ASYNC {Reture Process1 ()} دع T2 = ASYNC {RETURE PROCTION2 ()} دع T3 = ASYNC {RETURN WindowsProcess ()} دع التنفيذ = [T1؛ T2؛ T3] |> async.parallel |> async.runsynchronsly |> تجاهل
ما يجب القيام به في حالة يتطلب WindowsProcess Stathread؟ هل هذا ممكن مع هذا البناء؟
المحلول
إذا كان هناك مؤشر ترابط معين مع SyncrhonizationContext، مثل موضوع UI، فيمكنك القيام بذلك على سبيل المثال
// 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()
}
ولكن بشكل عام، ستبدأ المهام الموازية في ThreadPool.
لا تنتمي إلى StackOverflow