【发布时间】:2017-01-03 15:57:43
【问题描述】:
我正在构建一个包含 F# 文件的项目,并且在构建期间第 39 行出现错误:
这个表达式应该有类型 Async 但这里有类型 DispatcherOperation
open System
open System.Collections.Generic
open System.Collections.ObjectModel
open System.Linq
open System.Net
open System.Reactive.Disposables
open System.Runtime.CompilerServices
open System.Threading
open System.Windows
open System.Windows.Threading
open Microsoft.Practices.Unity
type IActivityContext<'TResult> = interface
abstract container: IUnityContainer
abstract Success: result:'TResult -> unit
abstract Error: error:Exception -> unit
abstract Cancel: unit -> unit
abstract RegisterCancellationCallback: callback:Action->IDisposable
end
[<Extension>]
type ActivityExtensions private() = class
[<Extension>]
static member StartViewActivity<'TResult>(container: IUnityContainer, callback: Action<IActivityContext<'TResult>>)= async{
let! ct = Async.CancellationToken
return! Async.FromContinuations(fun (success, error, cancel) ->
let context = {
new IActivityContext<'TResult> with
member this.container = container
member this.Success(result:'TResult) = success(result)
member this.Error(err:Exception) = error(err)
member this.Cancel() = cancel(new OperationCanceledException())
member this.RegisterCancellationCallback(callback: Action) =
ct.Register(callback) :> IDisposable
}
let disp = Application.Current.Dispatcher
Async.StartWithContinuations(
(* ERROR -> *) disp.InvokeAsync((fun() -> callback.Invoke(context))),
(fun()->()),
error,
cancel,
ct
)
)
}
end
有谁知道为什么会出现这个错误以及解决方案是什么?
【问题讨论】:
标签: f# async-await