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;