[release/6.0] Check BackgroundService.ExecuteTask for null (#60177)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Fri, 8 Oct 2021 19:09:07 +0000 (12:09 -0700)
committerGitHub <noreply@github.com>
Fri, 8 Oct 2021 19:09:07 +0000 (12:09 -0700)
commitabeae907c8bd59ccc3cd8accb4e2934355603bc4
treea69770e8d668f736c4c5a86bf3d4cf98d6bbbd9a
parentfba3f131d8a2f783f6095b75fddaf0c9c97e51c4
[release/6.0] Check BackgroundService.ExecuteTask for null (#60177)

* Check BackgroundService.ExecuteTask for null

In some scenarios, derived classes might not have called base.StartAsync, and ExecuteTask will still be null. Ensure we don't fail in those cases.

Fix #60131

* PR feedback

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
src/libraries/Microsoft.Extensions.Hosting/src/Internal/Host.cs
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs