Copied to clipboard

Flag this post as spam?

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


  • frmi 1 post 71 karma points
    Apr 21, 2016 @ 07:35
    frmi
    0

    Save IContent from another thread

    Hi

    I'm writing a desktop client that allows the user to upload a spreadsheet with products. The spreadsheet is then parsed by the API and products are either created or updated and saved using the ContentService.

    Since this process is really slow my first solution was to set the timeout of the client webrequest to 5 minutes, but i don't like that solution. Instead i want to make the creation/updates in another thread. This solution i can not get to work since i get an ArgumentNullException when using ContentService.Save(IList

    A snipppet of my current code:

    var items = parser.Parse(); // Parse spreadsheet
    new Task(() =>
    {
      var products = new List<IContent>();
      for (var item in items)
      {
        if (item.IsValid())
        {
            var product = CreateOrUpdateProduct(parentId, item);
            products.Add(product);
        }
      }
      ApplicationContext.Current.Services.ContentService.Save(products);
    ).Start();
    

    Is it possible to do this?

Please Sign in or register to post replies

Write your reply to:

Draft