In my application I have some not so important tasks to perform upon a user action that may take a few seconds to complete (ie send an email). Because of this, I'd like to perform the task on a separate thread.
This is all pretty basic stuff, but I run into a problem when I want to access some Umbraco data in my separate thread. As far as I can tell I should use the UmbracoHelper to read Umbraco data, but this helper is unavailable from a separate thread.
For example, normally I'd use something like the following to get a specific content node to access it's url:
var page = Umbraco.TypedContentSingleAtXPath(string.Format("/SomeDocType"));
var url = page.url;
From my separate thread (in a static helper class) the Umbraco property is not available. Trying to create one using this code:
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
Doesn't work because you get a NullReferenceException with UmbracoContext.Current being null. It seems to me like this getting data out of Umbraco using the API should be very straightforward, but somehow I always seem to end up with these kinds of issues...
The ApplicationContext.Current.Services does contain a ContentService, but as I understand it, that is not quite used to query published content like the UmbracoHelper does. I can't for instance query by document type via XPath (afaik).
Accessing Umbraco data from other thread
In my application I have some not so important tasks to perform upon a user action that may take a few seconds to complete (ie send an email). Because of this, I'd like to perform the task on a separate thread.
This is all pretty basic stuff, but I run into a problem when I want to access some Umbraco data in my separate thread. As far as I can tell I should use the UmbracoHelper to read Umbraco data, but this helper is unavailable from a separate thread.
For example, normally I'd use something like the following to get a specific content node to access it's url:
From my separate thread (in a static helper class) the Umbraco property is not available. Trying to create one using this code:
Doesn't work because you get a NullReferenceException with UmbracoContext.Current being null. It seems to me like this getting data out of Umbraco using the API should be very straightforward, but somehow I always seem to end up with these kinds of issues...
Anyone have a suggestion on what else I can try?
Hi Robert,
Have you tried using the Umbraco API Services instead?
Thanks, Dan.
The ApplicationContext.Current.Services does contain a ContentService, but as I understand it, that is not quite used to query published content like the UmbracoHelper does. I can't for instance query by document type via XPath (afaik).
is working on a reply...