First of all, I apologize because of my foolish question, I really don't know much about F#. But I know that it makes thread handling significantly easier. However, seeing the language construct someone might wonder why C# should miss the coolness that is asynchronous workflows? What theoretical limitation does C# have that prevents the aforementioned feature from being introduced?
views:
149answers:
2There's always the coordination and concurrency runtime which provides a similar style in C#, but makes for some slightly weird looking code via unusual use of the yield
keyword. It's proved extremely handy for thread handling in C# and I'd recommend it for anything requiring more than trivial thread coordination.
I don't know the answer to your question, but regarding Concurrency and Coordination runtime - there are actually simpler alternatives (also based on yield return
). I wrote one article about it a long time ago and there is also Jefrey Richters "PowerThreading" library, which is surprisingly simple and powerful (and uses the same trick).
Asynchronous Programming in C# using Iterators - my article, which shows how to encode F# asynchronous workflows using C# iterators (very directly)
More AsyncEnumerator Features - discusses how PowerThreading library uses
yield return
for asynchronous programming (it uses slightly different programming model, but also very clean and simple, especially compared to CCR).
To answer the question whether it would be technically possible to have something like F# asynchronous workflows in C# - I'd say yes - it's actually an idea pretty similar to iterators (and as you can see, you can use C# iterators for asynchronous programming already!) though there would be some interesting problems to resolve.