add shutdownhook for CoreCLR

pull/8047/head
Jan Tattermusch 8 years ago
parent e4e30f8813
commit 93f62aff5f
  1. 14
      src/csharp/Grpc.Core/GrpcEnvironment.cs
  2. 1
      src/csharp/Grpc.Core/project.json
  3. 1
      templates/src/csharp/Grpc.Core/project.json.template

@ -351,11 +351,11 @@ namespace Grpc.Core
{
if (!hooksRegistered)
{
// TODO(jtattermusch): register shutdownhooks for CoreCLR as well
#if !NETSTANDARD1_5
AppDomain.CurrentDomain.ProcessExit += ShutdownHookHandler;
AppDomain.CurrentDomain.DomainUnload += ShutdownHookHandler;
#if NETSTANDARD1_5
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += (assemblyLoadContext) => { HandleShutdown(); };
#else
AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => { HandleShutdown(); };
AppDomain.CurrentDomain.DomainUnload += (sender, eventArgs) => { HandleShutdown(); };
#endif
}
hooksRegistered = true;
@ -363,9 +363,9 @@ namespace Grpc.Core
}
/// <summary>
/// Handler for AppDomain.DomainUnload and AppDomain.ProcessExit hooks.
/// Handler for AppDomain.DomainUnload, AppDomain.ProcessExit and AssemblyLoadContext.Unloading hooks.
/// </summary>
private static void ShutdownHookHandler(object sender, EventArgs e)
private static void HandleShutdown()
{
Task.WaitAll(GrpcEnvironment.ShutdownChannelsAsync(), GrpcEnvironment.KillServersAsync());
}

@ -38,6 +38,7 @@
"netstandard1.5": {
"dependencies": {
"NETStandard.Library": "1.6.0",
"System.Runtime.Loader": "4.0.0",
"System.Threading.Thread": "4.0.0"
}
}

@ -40,6 +40,7 @@
"netstandard1.5": {
"dependencies": {
"NETStandard.Library": "1.6.0",
"System.Runtime.Loader": "4.0.0",
"System.Threading.Thread": "4.0.0"
}
}

Loading…
Cancel
Save