locked
when can infinite loop occur in a plugin. How to avoid infinite loops in plugin code RRS feed

  • Question

  • HI

    When can infinite loop occur in a plugin.How to avoid loops in plugin code.

    regards

    Benarji

    
    

    Benarji Sandra-MS Dynamics CRM Developer

    Friday, September 14, 2012 5:38 PM

Answers

  • Here is a really good article that explains when an infinite loop can occur in MS CRM & a solution to the problem. 

    http://varghesedanny.com/2012/08/20/crm-2011-context-depth-issue/


    John Grace (Founder, North52) Simplifying CRM & xRM development
    How? Check out Formula Manager at, North52

    Friday, September 14, 2012 10:50 PM
  • Hi,

    An infinite plugin loop example is: You have a post-update plugin on an entity 'A' that updates something in entity 'B' and entity 'B' has a post update plugin that updates plugin 'A'. Or You have a post-update plugin on an entity 'A' that updates a field in the same entity 'A', when entity 'A' will be updated, it will result in another update of entity 'A' and this will go on and will result in infinite loop. 

    Now, lets come to 'How we can stop it from happening?' There is a property called Depth for Context object. You can use this property to check if you are heading to an infinite loop. If context.Depth > 1, then you have a case of plugin causing a call to itself. The Depth attribute increments each time a plugin causes another plugin to execute. So you could check the contact plugin context. Depth is not larger then 2 if you want it to still fire at least once from the account plugin. 

    Every time a running plug-in or Workflow issues a message request to the Web services that triggers another plug-in or Workflow to execute, the Depth property of the execution context is increased. If the depth property increments to its maximum value within the configured time limit, the platform considers this behavior an infinite loop and further plug-in or Workflow execution is aborted. The maximum depth (8) and time limit (one hour) are configurable by the Microsoft Dynamics CRM administrator.

     http://msdn.microsoft.com/en-us/library/cc151077.aspx


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful" Thanks, Imran Abbasi

    Friday, September 14, 2012 11:03 PM

All replies

  • Here is a really good article that explains when an infinite loop can occur in MS CRM & a solution to the problem. 

    http://varghesedanny.com/2012/08/20/crm-2011-context-depth-issue/


    John Grace (Founder, North52) Simplifying CRM & xRM development
    How? Check out Formula Manager at, North52

    Friday, September 14, 2012 10:50 PM
  • Hi,

    An infinite plugin loop example is: You have a post-update plugin on an entity 'A' that updates something in entity 'B' and entity 'B' has a post update plugin that updates plugin 'A'. Or You have a post-update plugin on an entity 'A' that updates a field in the same entity 'A', when entity 'A' will be updated, it will result in another update of entity 'A' and this will go on and will result in infinite loop. 

    Now, lets come to 'How we can stop it from happening?' There is a property called Depth for Context object. You can use this property to check if you are heading to an infinite loop. If context.Depth > 1, then you have a case of plugin causing a call to itself. The Depth attribute increments each time a plugin causes another plugin to execute. So you could check the contact plugin context. Depth is not larger then 2 if you want it to still fire at least once from the account plugin. 

    Every time a running plug-in or Workflow issues a message request to the Web services that triggers another plug-in or Workflow to execute, the Depth property of the execution context is increased. If the depth property increments to its maximum value within the configured time limit, the platform considers this behavior an infinite loop and further plug-in or Workflow execution is aborted. The maximum depth (8) and time limit (one hour) are configurable by the Microsoft Dynamics CRM administrator.

     http://msdn.microsoft.com/en-us/library/cc151077.aspx


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful" Thanks, Imran Abbasi

    Friday, September 14, 2012 11:03 PM