I created a F# library that returns this datatype
FSharpAsync<IEnumerable<Tupel<DateTime,string>>>
How do I access the FSharpAsync type so I can enumerate through the tuple from C# and print out the content?
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.
It is generally not recommended to expose F# types such as
FSharpAsyncin a public interface that will be used by C# clients (see F# component design guidelines). You can useAsync.StartAsTask(on the F# side) to expose the operation as aTask<T>that is easy to use from C#.In fact, I would also replace the tuple with a named type (that captures the meaning of the data structure). Tuples can be used in C#, but they are not idiomatic in C#:
Now, to expose the operation to C#, the best practice is to use a type with an overloaded static method. The method starts the operation as a task and one overload specifies cancellation token. The C# naming convention for these is to add
Asyncto the end of the name (which doesn’t overlap with F# which addsAsyncto the front):Your C# code can then use
Work.DoWorkAsync()and work with the task in the usual C# style. It will even work with theawaitkeyword that will be (probably) added to C# 5.