Bulk Operations with DynamicModuleManager in Threads

Posted by Community Admin on 04-Aug-2018 16:18

Bulk Operations with DynamicModuleManager in Threads

All Replies

Posted by Community Admin on 10-Jun-2016 00:00

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("Transaction0", 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("Transaction0", 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?

Posted by Community Admin on 27-Jun-2016 00:00
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
 
This thread is closed