NB: I am not a professional software developer but I do write a lot of code that doesn't make use of asynchronous anything, so I apologize if this question is really straight forward.
I am interfacing with a library written in C#. There is a particular function (lets call it 'func') that returns a 'Threading.Tasks.Task>'
I am building a library in F# that makes use of func. I tested the following piece of code in a console app and it worked fine.
let result =
func()
|> Async.AwaitTask
|> Async.RunSynchronously
|> Array.ofSeq
However, when I run it from a WinForms app (which is ultimately what I want to do), execution blocks in the form code and never returns.
So I messed around with the code and tried the following, which worked.
let result =
async{
let! temp =
func()
|> Async.AwaitTask
return temp
} |> Async.RunSynchronously |> Array.ofSeq
Why didn't the first snippet work? Why did the second snippet work? Is there anything on this page that would answer either of these questions? If so, it does not seem obvious. If not, can you point me to somewhere that does?