开发者

F# Type Inference and System.Object

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜