-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.cs
More file actions
47 lines (41 loc) · 1.17 KB
/
Person.cs
File metadata and controls
47 lines (41 loc) · 1.17 KB
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
47
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace AsyncAwaitExample
{
public class Person
{
private Dishes _dishes;
private Dishwasher _dishwasher;
public Person()
{
_dishes = new Dishes();
_dishwasher = new Dishwasher();
}
public void DoDishes()
{
Console.WriteLine("Doing dishes");
new Dishes().CleanDishes("Breakfast");
}
public void Read()
{
Console.WriteLine("Reading my favorite book");
}
public async Task DoDishesAsync(string dishesName)
{
Console.WriteLine("Starting the dishwasher");
await _dishwasher.DoDishesTask(dishesName);
}
public async Task<string> DoManyDishesAsync(List<string> dishesNames)
{
var tasks = new List<Task>();
foreach (var dishesName in dishesNames)
{
var task = _dishwasher.DoDishesTask(dishesName);
tasks.Add(task);
}
await Task.WhenAll(tasks);
return "All dishes are finished";
}
}
}