简体   繁体   中英

F# this expression was expected to have type EventHandler but here has type unit

In C# Xamarin iOS I can do this:

InvokeOnMainThread( () => { //do stuff here});

where the argument for InvokeOnMainThread is NSAction

In F# I have

InvokeOnMainThread ( fun _ -> //do stuff here)

but I am getting the error "this expression was expected to have type EventHandler but here has type unit". Why? How can I work around this?

F# compiler doesn't automatically convert an F# function to NSAction .

You can do it manually though:

InvokeOnMainThread (new NSAction(fun _ -> (* do stuff here *)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM