aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core/GrpcEnvironment.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp/Grpc.Core/GrpcEnvironment.cs')
-rw-r--r--src/csharp/Grpc.Core/GrpcEnvironment.cs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/csharp/Grpc.Core/GrpcEnvironment.cs b/src/csharp/Grpc.Core/GrpcEnvironment.cs
index 574e900a0e..3ed2df203d 100644
--- a/src/csharp/Grpc.Core/GrpcEnvironment.cs
+++ b/src/csharp/Grpc.Core/GrpcEnvironment.cs
@@ -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());
}