-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPUBound-Async-Sync.cs
More file actions
46 lines (43 loc) · 1004 Bytes
/
CPUBound-Async-Sync.cs
File metadata and controls
46 lines (43 loc) · 1004 Bytes
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Threading.Tasks;
namespace ConsoleApp5
{
class Program
{
static void Main(string[] args)
{
var test = AsyncTask(60);
sysncTask();
test.Wait();
Console.WriteLine("hello " + test);
}
private static void sysncTask()
{
Console.WriteLine("2. Task from Harshal Raverkar");
for (int i = 0; i <= 6; i++)
{
for (int j = i; j <= 6; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
private static async Task<float> AsyncTask(float v)
{
try
{
Console.WriteLine("Started CPU Bound asynchronous task on a background thread");
Console.WriteLine("1. Hello Harshal Raverkar");
var t = await Task.Run(() => v * 1.2f);
Console.WriteLine($"Finished Task. Total of ${v} after tax of 20% is ${t} ");
return t;
}
catch (Exception e)
{
e.ToString();
return 7;
}
}
}
}