0

不知道为什么我会收到上述错误,我知道它是因为 UpdateWorkflowAssociation 在 foreach 内部,但我需要这样一个简单的帮助将不胜感激

                        `siteName = "http://xyz";

                        newCleanupDays = 5;
                        assoCounter = 0;
                        using (wfSite = new SPSite(siteName))
                        {
                            using (wfWeb = wfSite.OpenWeb())
                            {

                               //wfList = wfWeb.Lists[libraryName];
                                SPListCollection collList = wfWeb.Lists; //Open Lists
                                SPWorkflowAssociation _wfAssociation = null;

                                foreach (SPList oList in collList)
                                {
                                    if (oList.WorkflowAssociations.Count > 0)
                                    {
                                        foreach (SPWorkflowAssociation a in oList.WorkflowAssociations)
                                        {
                                            if (a.Name != null || a.Name != string.Empty)
                                            {
                                                a.AutoCleanupDays = newCleanupDays;
                                                _wfAssociation = a;
                                                assoCounter++;
                                            }
                                            else
                                            {
                                                _wfAssociation = a;
                                            }

                                        }
                                        oList.UpdateWorkflowAssociation(_wfAssociation);
                                    }

                                }
                                System.Console.WriteLine("\n" + wfAssoName + ": " + assoCounter.ToString() + " workflow association(s) changed successfuly!\n");
                            }
                        }`
4

1 回答 1

1

代替

foreach (SPList oList in collList)

简单地写

foreach (SPList oList in collList.ToList())

这样,您将遍历在迭代期间未修改的副本但可以更新真实的集合。

于 2012-03-06T15:36:17.240 回答