-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
42 lines (36 loc) · 936 Bytes
/
Copy pathProgram.cs
File metadata and controls
42 lines (36 loc) · 936 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
internal class Program
{
public static void Main()
{
var mainClass = new MainClass();
mainClass.Run();
}
}
internal class MainClass
{
private ChildClass child;
public void Run()
{
child = new ChildClass();
child._onTimeOut += OnExceptionOccured;
while (true)
{
child.StartTimer();
var task = Task.Run(() => Thread.Sleep(500));
task.Wait();
}
}
private void OnExceptionOccured(object? sender, UnhandledExceptionEventArgs args)
{
Console.WriteLine(args.ExceptionObject.ToString());
}
}
internal class ChildClass
{
public async void StartTimer()
{
await Task.Run(() => Thread.Sleep(250));
_onTimeOut?.Invoke(this, new UnhandledExceptionEventArgs(new TimeoutException("Time ran out"), false));
}
public EventHandler<UnhandledExceptionEventArgs>? _onTimeOut;
}