I'm pretty new to async/await in C#. I've been trying to get into it for IO reasons.
Currently, I have a sync method and I want to call an async method called Yaml.ReadAsync()
within this method.
public static async Task<T> ReadAsync<T>(string fileLocation)
{
string yamlString = await Text.ReadAsync(fileLocation);
var obj = ReadString<T>(yamlString, true);
return obj;
}
I have two ways of calling this method.
1.
options = Task.Run(() => Yaml.ReadAsync<Dictionary<string, dynamic>>(filePath)).Result;
2.
options = Task.Run(async() => await Yaml.ReadAsync<Dictionary<string, dynamic>>(filePath)).Result;
Both seem to work fine but I wish to know the differences. For example, is the first one even being executed as async, or is the second one just awaiting the entire Yaml.ReadAsync() method?
I know I shouldn't be running IO operations in Task.Run, but this is more of a placeholder until I add async to the necessary methods.