D
Dan_Walters
Guest
Hi, I'm learning about await and async and I'm having some trouble with the implementation. I know the theory is that you use await and async on IO bound activities, the idea being that you release the current thread for other work while the IO operation executes. What I'm not sure about is the implementation. In the below code, won't the thread block on the first line in Main, waiting for result to return?
static void Main(string[] args)
{
string strValue = ReadOperation().Result;
Console.WriteLine(strValue);
}
public async static Task<string> ReadOperation()
{
var ret = await File.ReadAllTextAsync("C:\\Users\\user\\Desktop\\file.txt");
return ret;
}
Continue reading...
static void Main(string[] args)
{
string strValue = ReadOperation().Result;
Console.WriteLine(strValue);
}
public async static Task<string> ReadOperation()
{
var ret = await File.ReadAllTextAsync("C:\\Users\\user\\Desktop\\file.txt");
return ret;
}
Continue reading...