假设我需要在C#中处理一个F#计算,并且希望它们同步运行。在底层,以下两种方式有何区别呢?
public static T RunSync<T>(FSharpAsync<T> computation)
{
return FSharpAsync.RunSynchronously(computation,
timeout: FSharpOption<int>.None,
cancellationToken: FSharpOption<System.Threading.CancellationToken>.None
);
}
或者
public static T RunSync<T>(FSharpAsync<T> computation)
{
return FSharpAsync.StartAsTask(computation,
taskCreationOptions: FSharpOption<TaskCreationOptions>.None,
cancellationToken: FSharpOption<System.Threading.CancellationToken>.None
).Result;
}
如果这个问题看起来很简单,那我很抱歉,因为我对异步编程还很陌生!