Bulk Operations with DynamicModuleManager in Threads
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?
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