Cleanup CancellationToken code

This commit is contained in:
Justin Kotalik 2018-03-26 18:15:36 -07:00
parent 0716789523
commit 3eee8b8958
2 changed files with 3 additions and 12 deletions

View File

@ -17,9 +17,6 @@ namespace ANCMStressTestApp
{
public class Program
{
public static IApplicationLifetime AppLifetime;
public static CancellationTokenSource Cts = new CancellationTokenSource();
public static void Main(string[] args)
{
var host = new WebHostBuilder()
@ -32,14 +29,6 @@ namespace ANCMStressTestApp
.UseStartup<Startup>()
.Build();
AppLifetime = (IApplicationLifetime)host.Services.GetService(typeof(IApplicationLifetime));
AppLifetime.ApplicationStopping.Register(
() => {
Cts.Cancel();
Cts.Dispose();
}
);
host.Run();
}
}

View File

@ -171,7 +171,9 @@ namespace ANCMStressTestApp
// Get the WebSocket object
var ws = WebSocketProtocol.CreateFromStream(opaqueTransport, isServer: true, subProtocol: null, keepAliveInterval: TimeSpan.FromMinutes(2));
await Echo(ws, Program.Cts.Token);
var appLifetime = app.ApplicationServices.GetRequiredService<IApplicationLifetime>();
await Echo(ws, appLifetime.ApplicationStopping);
});
}