开发者

F# Type Inference and System.Object

开发者 https://www.devze.com 2022-12-14 20:56 出处:网络
I have a problem getting the following code to work. open System open System.ComponentModel open System.Threading

I have a problem getting the following code to work.

open System
open System.ComponentModel
open System.Threading

let triggerEvent (state : Object) = Console.Write("Do Something.")

let asyncContext = AsyncOperationManager.CreateOperation(null)
asyncContext.PostOperationCompleted(triggerEvent, null)

I get an error, that triggerEvent is of type 'a -> unit instead of SendOrPostCallback. S开发者_开发百科endOrPostCallback is of type Object -> unit. I am wondering why triggerEvent is of type 'a -> unit instead of Object -> unit. I explicitly declared state as Object and still it is 'a.

Any suggestions? Thank you.


I'm not an expert on threading, but if PostOperationCompleted expects a SendOrPostCallback, try wrapping your triggerEvent like this: replace

asyncContext.PostOperationCompleted(triggerEvent, null)

by

asyncContext.PostOperationCompleted(new SendOrPostCallback(triggerEvent), null)
0

精彩评论

暂无评论...
验证码 换一张
取 消