More in this section
Forums / Developing with Sitefinity / ICommentEvent runs TWICE in ONE comment

ICommentEvent runs TWICE in ONE comment

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
4 posts, 0 answered
  1. Nghi
    Nghi avatar
    8 posts
    Registered:
    05 Apr 2016
    23 May 2016
    Link to this post

    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).

     

    Thanks

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    17 Aug 2017
    26 May 2016
    Link to this post
    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:

    http://docs.sitefinity.com/for-developers-comments-events#icommentcreatedevent

    Regards,
    Sabrie Nedzhip
    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
     
  3. Nghi
    Nghi avatar
    8 posts
    Registered:
    05 Apr 2016
    03 Jun 2016
    Link to this post
    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?
  4. Njabulo
    Njabulo avatar
    1 posts
    Registered:
    15 Apr 2013
    23 Sep 2016
    Link to this post
    Any solution for this yet?
4 posts, 0 answered