Dynamics CRM 2011 PostUpdate 陷入无限循环

Dynamics CRM 2011 PostUpdate gets caught an infinite loop

我正在开发一个插件。当我在 PostUpdate 插件中更新实体时,PreUpdate 插件被触发 PostUpdate 插件并陷入无限循环。

如何打破无限循环?

使用Depth属性跳出死循环。

在您的插件中,检查 PluginExecutionContext.Depth 是否大于 1,如果是,则 return。

相关代码片段。

if (localContext.PluginExecutionContext.Depth > 1)
{
    return;
}

我想补充一点,CRM 插件陷入无限循环的主要原因之一是插件使用 CRM 服务来更新首先触发插件的记录。

与其使用部门检查递归 属性,通常更好的方法是使用 Target Image 简单地执行对 CRM 记录的更新。

以下 post 解决了一个类似的问题:crm 2011 Updating the record that fired the Plugin in post-sync and post-async stage

有些情况下这种递归是不可避免的;但通常值得理解为什么会发生递归以及是否可以避免递归。