Cleanup CancellationToken code
This commit is contained in:
parent
0716789523
commit
3eee8b8958
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue