提交 d12aad70 编写于 作者: D Don Syme 提交者: Kevin Ransom (msft)

fix 3171 (#3182)

上级 36a3f0f7
......@@ -92,7 +92,10 @@ module internal RoslynHelpers =
member __.Proceed = not isStopped
member __.Stop() = isStopped <- true
// This is like Async.StartAsTask, but if cancellation occurs we explicitly associate the cancellation with cancellationToken
// This is like Async.StartAsTask, but
// 1. if cancellation occurs we explicitly associate the cancellation with cancellationToken
// 2. if exception occurs then set result to Unchecked.defaultof<_>, i.e. swallow exceptions
// and hope that Roslyn copes with the null
let StartAsyncAsTask (cancellationToken: CancellationToken) computation =
let tcs = new TaskCompletionSource<_>(TaskCreationOptions.None)
let barrier = VolatileBarrier()
......@@ -102,10 +105,24 @@ module internal RoslynHelpers =
Async.StartWithContinuations(
async { do! Async.SwitchToThreadPool()
return! computation },
continuation=(fun result -> disposeReg(); tcs.TrySetResult(result) |> ignore),
exceptionContinuation=(function :? OperationCanceledException -> disposeReg(); tcs.TrySetCanceled(cancellationToken) |> ignore
| exn -> disposeReg(); tcs.TrySetException(exn) |> ignore),
cancellationContinuation=(fun _oce -> disposeReg(); tcs.TrySetCanceled(cancellationToken) |> ignore),
continuation=(fun result ->
disposeReg()
tcs.TrySetResult(result) |> ignore
),
exceptionContinuation=(fun exn ->
disposeReg()
match exn with
| :? OperationCanceledException ->
tcs.TrySetCanceled(cancellationToken) |> ignore
| exn ->
System.Diagnostics.Trace.WriteLine("Visual F# Tools: exception swallowed and not passed to Roslyn: {0}", exn.Message)
let res = Unchecked.defaultof<_>
tcs.TrySetResult(res) |> ignore
),
cancellationContinuation=(fun _oce ->
disposeReg()
tcs.TrySetCanceled(cancellationToken) |> ignore
),
cancellationToken=cancellationToken)
task
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册