Threading publishing of data in custom module
This works fine when I run it on the main thread. However when threaded I get the following error:
dynamicModuleManager.Lifecycle.Publish(currentEventItem);
Object references between two different object scopes are not allowed. The object 'Telerik.Sitefinity.DynamicModules.Model.DynamicContentUrlData' is already managed by 'ObjectScopeImpl 0x37 OpenAccessRuntime.EnlistableObjectScope' and was tried to be managed again by 'ObjectScopeImpl 0x3a OpenAccessRuntime.EnlistableObjectScope'.
See custom module code below:
public delegate void Worker();
private static Thread _worker;
protected override void OnInit(EventArgs e)
base.OnInit(e);
InitSyncWorker(ThreadSync);
public void InitSyncWorker(Worker work)
_worker = new Thread(new ThreadStart(work));
_worker.Start();
public void ThreadSync()
lock (EventDataLocker.Lockable)
var timeDiff = DateTime.Now.Subtract(EventDataLocker.DateTimeLastSynced);
if (timeDiff.TotalMinutes >= 20)
StartSync();
public void StartSync()
const string providerName = "OpenAccessProvider";
var dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
var webClient = new WebClient();
//var obj //get data obj here
//deserialize obj
foreach (var e in obj.body.Events)
UpdateEvent(CurrentEventItem[0], Event);
private void UpdateEvent(DynamicContent currentEventItem, EventData Event)
const string providerName = "OpenAccessProvider";
var dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
currentEventItem.SetValue("Title", Event.name);
currentEventItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
currentEventItem.SetValue("PublicationDate", DateTime.Now);
currentEventItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft");
// You need to call SaveChanges() in order for the items to be actually persisted to data store
dynamicModuleManager.Lifecycle.Publish(currentEventItem); //crashes on this line
dynamicModuleManager.SaveChanges();
Hi Nicolas,
Based on the information provided I can only conclude that the error is thrown due to the fact you are not authenticated in the thread you wish to update. The dynamicModuleManager.Lifecycle.Publish() method requires authentication.
Additionally, can you elaborate a bit on the scenario you have.
Regards,
Ivan D. Dimitrov
Telerik