add shutdownhook for CoreCLR

pull/8107/head
Jan Tattermusch 9 years ago
parent 826c8d7985
commit 6555499306
  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

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

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

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

Loading…
Cancel
Save