Click run to see the console output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
·using System;
using System.Threading.Tasks;
namespace AsyncApp
{
class Program
{
static void Main(string[] args)
{
var totalAfterTax = CalculateTotalAfterTaxAsync(70);
DoSomethingSynchronous();
totalAfterTax.Wait();
Console.ReadLine();
}
private static void DoSomethingSynchronous()
{
Console.WriteLine("Doing some synchronous work");
}
static async Task<float> CalculateTotalAfterTaxAsync(float value)
{
Console.WriteLine("Started CPU Bound asynchronous task on a background thread");
var result = await Task.Run(() => value * 1.2f);
Console.WriteLine($"Finished Task. Total of ${value} after tax of 20% is ${result} ");
return result;
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX