Async Concepts
Awaited Result
Treat an awaited operation as a value that becomes available later.
async
After an awaited operation completes, the rest of the method can use the returned value like any other local variable.
Awaited Result
AwaitedResult.cs
Replay: real traced execution (multi-file project)
using System;
class Program
{
static int FetchScore(int storedScore)
{
return storedScore;
}
static void Main()
{
int storedScore = 80;
int score = FetchScore(storedScore);
string result = score >= 60 ? "pass" : "retry";
Console.WriteLine($"score={score}");
Console.WriteLine($"result={result}");
}
}
using System;
class Program
{
static int FetchScore(int storedScore)
{
return storedScore;
}
static void Main()
{
int storedScore = 40;
int score = FetchScore(storedScore);
string result = score >= 60 ? "pass" : "retry";
Console.WriteLine($"score={score}");
Console.WriteLine($"result={result}");
}
}
using System;
class Program
{
static int FetchScore(int storedScore)
{
return storedScore;
}
static void Main()
{
int storedScore = 100;
int score = FetchScore(storedScore);
string result = score >= 60 ? "pass" : "retry";
Console.WriteLine($"score={score}");
Console.WriteLine($"result={result}");
}
}
storedScore ← 80
10static void Main()11{12 int storedScore→ 80 = 80; //@storedScore=40, 10013 int score = FetchScore(storedScore80);14 string result = score >= 60 ? "pass" : "retry";static int FetchScore(int storedScore)
4{5 static int FetchScore(int storedScore80)6 {7 return storedScore80;8 }score ← 80, result ← pass
12 int storedScore = 80; //@storedScore=40, 10013 int score→ 80 = FetchScore(storedScore80);14 string result→ pass = score80 >= 60 ? "pass" : "retry";1516 Console.WriteLine($"score={score80}");17 Console.WriteLine($"result={resultpass}");18}outputscore=80 result=pass
storedScore ← 40
10static void Main()11{12 int storedScore→ 40 = 40;13 int score = FetchScore(storedScore40);14 string result = score >= 60 ? "pass" : "retry";static int FetchScore(int storedScore)
4{5 static int FetchScore(int storedScore40)6 {7 return storedScore40;8 }score ← 40, result ← retry
12 int storedScore = 40;13 int score→ 40 = FetchScore(storedScore40);14 string result→ retry = score40 >= 60 ? "pass" : "retry";1516 Console.WriteLine($"score={score40}");17 Console.WriteLine($"result={resultretry}");18}outputscore=40 result=retry
storedScore ← 100
10static void Main()11{12 int storedScore→ 100 = 100;13 int score = FetchScore(storedScore100);14 string result = score >= 60 ? "pass" : "retry";static int FetchScore(int storedScore)
4{5 static int FetchScore(int storedScore100)6 {7 return storedScore100;8 }score ← 100, result ← pass
12 int storedScore = 100;13 int score→ 100 = FetchScore(storedScore100);14 string result→ pass = score100 >= 60 ? "pass" : "retry";1516 Console.WriteLine($"score={score100}");17 Console.WriteLine($"result={resultpass}");18}outputscore=100 result=pass