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

Forums / Developing with Sitefinity / Threading publishing of data in custom module

Threading publishing of data in custom module

2 posts, 0 answered
  1. Nicolas
    Nicolas avatar
    2 posts
    Registered:
    12 Nov 2008
    09 Jun 2014
    Link to this post

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

  2. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    12 Jun 2014
    Link to this post
    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
     
2 posts, 0 answered