Skip to content
Snippets Groups Projects
Commit 65554993 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

add shutdownhook for CoreCLR

parent 826c8d79
No related branches found
No related tags found
No related merge requests found
...@@ -352,11 +352,11 @@ namespace Grpc.Core ...@@ -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 ...@@ -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 @@ ...@@ -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 @@ ...@@ -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"
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment