Copied to clipboard

Flag this post as spam?

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


  • Rick 92 posts 278 karma points
    Jan 31, 2016 @ 10:22
    Rick
    0

    Parallel.ForEach UmbracoContext is null

    Hi,

    I'm using Umbraco 7.3.5 and I am doing some process heavy looping with approx 2.5k nodes.

    Within each node, I'm setting a bunch of values to necessary properties for that specific node.

    The process is taking quite some time when looping using a standard foreach - so I'd like to improve this as this scheduled task is going to run daily.

    I came across the Parallel.ForEach (although not used it before) method and managed to dramatically improve the process speed. However, when I come to SaveAndPublish the node (inside the loop) - I get a null reference exception on this line:

    UmbracoContext.Application.Services.ContentService.SaveAndPublishWithStatus(content, 0, false);
    

    I've noticed that during the first iteration, the node is successfully saved and published, but when I get to subsequent iterations, the null reference exception occurs.

    What is strange is when I check the UmbracoContext at this point, it is not null!

    Please can anyone help with this?

    Many thanks,

    Rick

Please Sign in or register to post replies

Write your reply to:

Draft