-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkerTwo.cs
46 lines (31 loc) · 1.51 KB
/
WorkerTwo.cs
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 MediatR;
using Veronica.Sandbox.WS.Interfaces;
namespace Veronica.Sandbox.WS {
public class WorkerTwo : BackgroundService, INotificationHandler<SimpleMsg> {
private readonly ISingletonClass singClass;
private Guid id;
public WorkerTwo(ISingletonClass singletonClass) {
singClass = singletonClass;
id = Guid.NewGuid();
Console.WriteLine($"WorkerTwo loaded at: {DateTimeOffset.Now}");
Console.WriteLine($"Worker Guid: --------------- {id}");
}
public override Task StartAsync(CancellationToken cancellationToken) {
Console.WriteLine($"WorkerTwo Started at: {DateTimeOffset.Now}");
return base.StartAsync(cancellationToken);
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
Console.WriteLine($"WorkerTwo running at: {DateTimeOffset.Now}");
await Task.Delay(1000, stoppingToken);
Console.WriteLine("WorkerTwo Execution Ended...", 2, 2);
}
public override Task StopAsync(CancellationToken cancellationToken) {
Console.WriteLine($"WorkerTwo stopped at: {DateTimeOffset.Now}");
return base.StopAsync(cancellationToken);
}
public Task Handle(SimpleMsg notification, CancellationToken cancellationToken) {
Console.WriteLine($"WorkerTwo received notification {notification.msg} at: {DateTimeOffset.Now}");
return Task.CompletedTask;
}
}
}