From 58e07a8b2ba4f86b752c83cd8462ce5570b4ea4e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 19 Feb 2016 21:20:00 +0000 Subject: [PATCH] Put threads into background before starting --- .../Infrastructure/KestrelThread.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index 5b7d998f8e..d8cb804fbb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -52,6 +52,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); _thread.Name = "KestrelThread - libuv"; +#if !DEBUG + // Mark the thread as being as unimportant to keeping the process alive. + // Don't do this for debug builds, so we know if the thread isn't terminating. + _thread.IsBackground = true; +#endif QueueCloseHandle = PostCloseHandle; QueueCloseAsyncHandle = EnqueueCloseHandle; } @@ -79,12 +84,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel public void Stop(TimeSpan timeout) { -#if !DEBUG - // Mark the thread as being as unimportant to keeping the process alive. - // Don't do this for debug builds, so we know if the thread isn't terminating. - _thread.IsBackground = true; -#endif - if (!_initCompleted) { return;