+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Bulk Operations with DynamicModuleManager in Threads

Bulk Operations with DynamicModuleManager in Threads

2 posts, 0 answered
  1. Kyle
    Kyle avatar
    1 posts
    Registered:
    29 Jun 2015
    10 Jun
    Link to this post

    Will DynamicModuleManager work in threads? Here is a specific example....

    This function below runs to completion (takes about 90 minutes) without a problem. 

    int transCount = 0;
    string transName = string.Format("Transaction{0}", transCount);
    DynamicModuleManager dmmBatches = DynamicModuleManager.GetManager(DynamicModuleManager.GetDefaultProviderName(), transName);
    dmmBatches.Provider.SuppressSecurityChecks = true;
    Type inventoryType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Inventories.Inventory");
    List<DynamicContent> inventoryRecords = dmmBatches.GetDataItems(inventoryType).Where(x => x.Status == ContentLifecycleStatus.Master).ToList();
    int count = 0;
    inventoryRecords.ForEach(invRecord =>
    {
    dmmBatches.DeleteDataItem(inventoryType, invRecord.Id);
    count++;
    if (count % 5 == 0)
    {
    TransactionManager.CommitTransaction(transName);
    transCount++;
    transName = string.Format("Transaction{0}", transCount);
    dmmBatches = DynamicModuleManager.GetManager(DynamicModuleManager.GetDefaultProviderName(), transName);
    dmmBatches.Provider.SuppressSecurityChecks = true;
    }
    });

    However, once we put it into it's own thread (background process) like below:

    Thread inventoryThread = new Thread(() => {code});
    inventoryThread.Start();

    The thread runs successfully for a short period of time, then we get this error:
    "The referenced OpenAccessContext or 'IObjectScope' is already closed (UnsynchronizedPMProxy)"

    I think something like 500 records get updated before this error occurs.

     

    Any idea why this would be disposed in the middle of processing in a thread, but runs fine in the main application?

  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    22 Sep 2016
    27 Jun
    Link to this post
    Hi,

    Running any manager in Sitefinity in threads by initializing or passing the manager class reference to a thread will not work. It outputs the IObjectScope exception. The way to go here is to spawn multiple webservice requests in many threads. Each instance of the webservice will handle the work with DynamicModuleManager without the current issue.

    More info on how to create and register a webservice in Sitefinity refer to this documentation.

    Regards,
    Stanislav Velikov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered