Copied to clipboard

Flag this post as spam?

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


  • John Churchley 272 posts 1258 karma points c-trib
    May 24, 2016 @ 08:23
    John Churchley
    0

    Using MediaService on Application Start without delaying project initialising

    Hi,

    I'm trying to do a bulk operation on a huge amount of media items. I'm trying to do it asynchronously in the application start up so it doesn't take 5 minutes for the site to start on a app pool refresh. I'm using the media service but the media object is coming back null. Without it being called asynchronously it works fine.

    I'm getting a an exception of type 'System.ArgumentNullException' occurred in System.Web.dll but was not handled in user code. Although when I debug I can see object properties being populated.

    Using

    public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext){
                    System.Threading.Tasks.Task.Run(() => Build(applicationContext));
    }
    
    private void Build(ApplicationContext applicationContext)
    {
     var cs = applicationContext.Services.ContentService;
     var node = cs.GetById(225353);
     node.Name = test;
     cs.SaveAndPublishWithStatus(node);
    }
    

    Error occurring on the SaveAndPublishWithStatus method

Please Sign in or register to post replies

Write your reply to:

Draft