2

次のコードフラグメントについて考えてみます。

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

実行させてください=
    [t1; t2; t3]
    |> Async.Parallel
    |> Async.RunSynchronously
    |>無視する

windowsProcessにSTATHREADが必要な場合はどうすればよいですか?この構造でこれは可能ですか?

4

1 に答える 1

5

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() 
    }

ただし、通常、並列タスクはスレッドプールで開始されます。

于 2009-07-12T02:14:19.900 に答える