From 79623a8a6754c62107989b6d0db71cc2f3e651f4 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 29 Sep 2016 13:53:35 +0200 Subject: [PATCH] Fix BackgroundTaskRunner for tests without an app context --- src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs b/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs index b67c2c08ac..81487034e1 100644 --- a/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs +++ b/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs @@ -112,12 +112,15 @@ namespace Umbraco.Web.Scheduling if (options.Hosted) HostingEnvironment.RegisterObject(this); - if (mainDomRelease != null) + if (mainDomInstall != null || mainDomRelease != null) { - var mainDom = ApplicationContext.Current.MainDom; + var appContext = ApplicationContext.Current; + var mainDom = appContext == null ? null : appContext.MainDom; var reg = mainDom == null || ApplicationContext.Current.MainDom.Register(mainDomInstall, mainDomRelease); if (reg == false) - _isCompleted = _terminated = true; + _isCompleted = _terminated = true; + if (reg && mainDom == null && mainDomInstall != null) + mainDomInstall(); } if (options.AutoStart && _terminated == false)