-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathApplication.cs
More file actions
37 lines (27 loc) · 866 Bytes
/
Application.cs
File metadata and controls
37 lines (27 loc) · 866 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
namespace Sample.Hybrid.ConsoleApp;
using Microsoft.Extensions.Hosting;
using Sample.Hybrid.ConsoleApp.Domain;
public class MainApplication : IHostedService
{
private bool canRun = true;
public async Task CustomerDoesSomeStuff()
{
while (canRun)
{
var customer = new Customer("John", "Doe");
await customer.ChangeEmail("john@doe.com");
await Task.Delay(2000);
}
}
public Task StartAsync(CancellationToken cancellationToken)
{
var task = Task.Run(CustomerDoesSomeStuff);
Console.WriteLine("Application started. Press any key to terminate.");
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
canRun = false;
return Task.CompletedTask;
}
}