IPublishedContent.Url() throwing scope error when called in background running task (v10)
I have a long running background task which I fire and forget with IBackgroundTaskQueue.QueueBackgroundWorkItem(token => Task.Run(()=>task))
In the process, the task gathers some meta data from content nodes, thus calling IPublishedContent.Url() to get their url.
As this is a long running task in the background I set it up with it's own scope like this:
using(ExecutionContext.SuppressFlow()){
using(_serviceScopeFactory.CreateAsyncScope()){
// long running work here ..
}
}
However, when trying to get the url for a node I get this:
System.InvalidOperationException: The Scope
34e2e8a7-065e-4169-82ff-3f00f1751d62 being disposed is not the Ambient
Scope 34e2e8a7-065e-4169-82ff-3f00f1751d62. This typically indicates
that a child Scope was not disposed, or flowed to a child thread that
was not awaited, or concurrent threads are accessing the same Scope
(Ambient context) which is not supported. If using Task.Run (or
similar) as a fire and forget tasks or to run threads in parallel you
must suppress execution context flow with
ExecutionContext.SuppressFlow() and ExecutionContext.RestoreFlow().
The error is thrown by LocalizationService:
at Umbraco.Cms.Infrastructure.Scoping.Scope.Dispose()
at Umbraco.Cms.Core.Services.LocalizationService.GetDefaultLanguageIsoCode()
IPublishedContent.Url() throwing scope error when called in background running task (v10)
I have a long running background task which I fire and forget with
IBackgroundTaskQueue.QueueBackgroundWorkItem(token => Task.Run(()=>task))
In the process, the task gathers some meta data from content nodes, thus calling
IPublishedContent.Url()
to get their url.As this is a long running task in the background I set it up with it's own scope like this:
However, when trying to get the url for a node I get this:
The error is thrown by LocalizationService:
Any idea what am I missing here?
is working on a reply...