Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert Mulder 79 posts 270 karma points c-trib
    Sep 24, 2014 @ 15:24
    Robert Mulder
    0

    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:

    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...

    Anyone have a suggestion on what else I can try?

  • Dan Lister 416 posts 1973 karma points c-trib
    Sep 24, 2014 @ 15:30
    Dan Lister
    0

    Hi Robert,

    Have you tried using the Umbraco API Services instead?

    ApplicationContext.Services
    

    Thanks, Dan.

  • Robert Mulder 79 posts 270 karma points c-trib
    Sep 24, 2014 @ 15:40
    Robert Mulder
    0

    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).

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies