F# 类型推断和 System.Object
我在使用以下代码时遇到问题。
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)
我收到一个错误,triggerEvent 的类型为 'a ->单元而不是 SendOrPostCallback。 SendOrPostCallback 的类型为 Object ->单元。我想知道为什么triggerEvent 的类型是 'a ->单位而不是对象 ->单元。我明确地将状态声明为对象,但它仍然是“a”。
有什么建议吗?谢谢。
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.
SendOrPostCallback 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是线程方面的专家,但如果 PostOperationCompleted 需要 SendOrPostCallback,请尝试像这样包装您的 triggerEvent:
替换
为
I'm not an expert on threading, but if PostOperationCompleted expects a SendOrPostCallback, try wrapping your triggerEvent like this:
replace
by