Is the asynchronous implementation in C# 4.5 exactly the same as in F# 2 in the way threads are used?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are different. The main difference is that C# uses standard .NET
Task<T>to represent asynchronous computations while F# uses its own type calledAsync<T>.More specifically, the key differences are:
A C# async method creates a
Task<T>that is immediately started (hot task model) while F# creates a computation that you have to start explicitly (generator model). This means that F# computations are easier to compose (you can write higher level abstractions).In F# you also get better control over how is the computation started. You can start a computation using
Async.Startto start it in the background orAsync.StartImmediateto start it on the current thread.F# asynchronous workflows support cancellation automatically, so you do not have to pass
CancellationTokenaround.Perhaps another consequence of the first point is that F# async workflows also support tail-recursion, so you can write recursive workflows (this would not work easily in C#, but C# does not use this programming style)
I wrote a more detailed article about this topic: Asynchronous C# and F# (II.): How do they differ?