aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2016-09-09 11:43:52 +0200
committerGravatar Jan Tattermusch <jtattermusch@google.com>2016-09-15 18:18:26 +0200
commit6555499306be65b2772a0dadccd9e2ecb66c6485 (patch)
tree85eda4923a1a15dcb07d306adc6cf50aa9099511 /src/csharp/Grpc.Core
parent826c8d798564b2738a006c1421fcf8710ffd155f (diff)
add shutdownhook for CoreCLR
Diffstat (limited to 'src/csharp/Grpc.Core')
-rw-r--r--src/csharp/Grpc.Core/GrpcEnvironment.cs14
-rw-r--r--src/csharp/Grpc.Core/project.json1
2 files changed, 8 insertions, 7 deletions
diff --git a/src/csharp/Grpc.Core/GrpcEnvironment.cs b/src/csharp/Grpc.Core/GrpcEnvironment.cs
index eeed699712..3538633d61 100644
--- a/src/csharp/Grpc.Core/GrpcEnvironment.cs
+++ b/src/csharp/Grpc.Core/GrpcEnvironment.cs
@@ -352,11 +352,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;
@@ -364,9 +364,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());
}
diff --git a/src/csharp/Grpc.Core/project.json b/src/csharp/Grpc.Core/project.json
index 938db0ffc7..8cdb1720a4 100644
--- a/src/csharp/Grpc.Core/project.json
+++ b/src/csharp/Grpc.Core/project.json
@@ -38,6 +38,7 @@
"netstandard1.5": {
"dependencies": {
"NETStandard.Library": "1.6.0",
+ "System.Runtime.Loader": "4.0.0",
"System.Threading.Thread": "4.0.0"
}
}