-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormalEvent.cs
More file actions
38 lines (34 loc) · 1.05 KB
/
NormalEvent.cs
File metadata and controls
38 lines (34 loc) · 1.05 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventsToAwaitables
{
public static class NormalEventDemo
{
public static void Run()
{
// Used to be sure that the Start method is called at the return of this method
ManualResetEvent handle = new ManualResetEvent(false);
var game = new Game();
StartGameAfter1Second(game);
game.Started += () =>
{
Console.WriteLine("Started");
Console.WriteLine($"Handler thread {Thread.CurrentThread.ManagedThreadId}");
handle.Set();
};
handle.WaitOne();
}
static void StartGameAfter1Second(Game game)
{
new Thread(() =>
{
Thread.Sleep(1000);
Console.WriteLine($"Event raiser thread {Thread.CurrentThread.ManagedThreadId}");
game.Start();
}).Start();
}
}
}