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)
精彩评论