ICommentEvent runs TWICE in ONE comment - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

ICommentEvent runs TWICE in ONE comment

  • ICommentEvent runs TWICE in ONE comment
  • I have these code, according to document from sitefinity:



    protected void Application_Start(object sender, EventArgs e)
                Bootstrapper.Initialized += new EventHandler<ExecutedEventArgs>(Bootstrapper_Initialized);


    public void Bootstrapper_Initialized(object sender, ExecutedEventArgs args)
                if (args.CommandName == "Bootstrapped")
                    EventHub.Subscribe<ICommentEvent>(evt => CommentsEvent.CommentEventHandler(evt));


    and the handler:


     public static void CommentEventHandler(ICommentEvent evt)
                // My code here


    The problem is this handler always runs twice when a comment event happens (post a comment or approve a comment). 


    Could you please tell me why this happens and any possible way to avoid this? (I don't believe static boolean is a good idea).



  • Hello,

    Can you please try to use the below sample code which will execute only once after a comment has been created:

    protected void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
                if (e.CommandName == "Bootstrapped")
                    EventHub.Subscribe<ICommentCreatedEvent>(evt => CommentsEventHandler(evt));
            public void CommentsEventHandler(ICommentCreatedEvent eventInfo)
                     // your custom code

    Please also check the below section from our documentation for more details on this:


    Sabrie Nedzhip
    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
  • Thanks Sabrie.
    I tried this before and the problem is this handler doesn't catch event when i publish a comment (from sitefinity back-end). 
    Any solutions?
  • Any solution for this yet?