Threading publishing of data in custom module

Posted by Community Admin on 04-Aug-2018 10:07

Threading publishing of data in custom module

All Replies

Posted by Community Admin on 09-Jun-2014 00:00

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();
       

Posted by Community Admin on 12-Jun-2014 00:00

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

 
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