Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:17:40+00:00 2026-06-10T11:17:40+00:00

I have created a TcmExtension named WorkflowEventSystem that has an event handler subscribed to

  • 0

I have created a TcmExtension named WorkflowEventSystem that has an event handler subscribed to the FinishProcess event. The purpose of this event is to schedule for publish all dependencies (i.e. pages) of the associated workflow subject.

The problem I am having is that even though the event triggers at the right time (a workflow process is completed), and all the items that are supposed to be scheduled for publish are, the PublishScheduler object created by the event never seems to go out of scope, and as such the WorkflowEventSystem object does not either.

Is there something I am missing about how the Event System works that would cause these objects to live on forever? I’ve included what I consider the relevant code below (some parts summarized). Thanks for any help.

Here’s most of the actual TcmExtension:

public class WorkflowEventSystem : TcmExtension
{
    public WorkflowEventSystem()
    {
        this.Subscribe();
    }

    public void Subscribe()
    {
        EventSystem.Subscribe<ProcessInstance, FinishProcessEventArgs>(ScheduleForPublish, EventPhases.All);
    }
}

ScheduleForPublish creates a PublishScheduler object (class I created):

private void ScheduleForPublish(ProcessInstance process, FinishProcessEventArgs e, EventPhases phase)
{
    if(phase == EventPhases.TransactionCommitted)
    {
        PublishScheduler publishScheduler = new PublishScheduler(process);
        publishScheduler.ScheduleForPublish(process);
        publishScheduler = null;  // worth a try
    }
}

The ScheduleForPublish method looks similar to this:

public void ScheduleForPublish(ProcessInstance process)
{
    using(Session session = new Session("ImpersonationUser"))
    {
        var publishInstruction = new PublishInstruction(session);
        // Set up some publish Instructions

       var publicationTargets = new List<PublicationTarget>();
       // Add a PublicationTarget here by tcm id

       IList<VersionedItem> itemsToPublish = new List<VersionedItem>();
       // Add the items we want to publish by calling GetUsingItems(filter)
       // on the workflow process' subject

       //Publish the items
       PublishEngine.Publish(itemsToPublish.Cast<IdentifiableObject>(), publishInstruction, publishTargets);
    }    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:17:42+00:00Added an answer on June 10, 2026 at 11:17 am

    Life-cycle management for TcmExtension classes is quite simple:

    1. when you call Subscribe the TcmExtension object you specify is added to an internal list of subscriptions

    2. when you later call Unsubscribe the same TcmExtension object is removed from the list of subscriptions

    Since you never call Unsubscribe your WorkflowEventSystem is never removed and thus will never be garbage collected by .NET. And since your WorkflowEventSystem holds a reference to the PublishScheduler instance it created, that one will thus also never be cleaned up.

    The proper boilerplate for a custom TcmExtension is:

    public class WorkflowEventSystem : TcmExtension, IDisposable
    {
        EventSubscription _subscription;
    
        public WorkflowEventSystem()
        {
            this.Subscribe();
        }
    
        public void Subscribe()
        {
             _subscription = EventSystem.Subscribe<ProcessInstance, 
                 FinishProcessEventArgs>(ScheduleForPublish, EventPhases.All);
        }
    
        public void Dispose()
        {
            _subscription.Unsubscribe();
        }
    }
    

    Nuno also gave a longer example (handling multiple subscribers) in this article:
    http://nunolinhares.blogspot.nl/2012/07/validating-content-on-save-part-1-of.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have created a custom navigation menu in wordpress that has some pages and some
I have created a UserControl that has a ListView in it. The ListView is
I have created some JQuery that will expand a div 'popup' on hover and
I have created an EDMX in visual studio 2010 SP1. It has been built
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a custom post type named People. I have created a page
I have created a function that shows/hides different messages according to a combination of
I have created a dialog and got a problem that only part of the
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created some forms using zendframework on my local machine that send the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.