gpt4 book ai didi

vb.net - 该枚举器绑定(bind)到的列表已被修改

转载 作者:行者123 更新时间:2023-12-02 21:49:24 26 4
gpt4 key购买 nike

我这里有这段代码,在下一个语句中它给了我一个错误:

List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.

我真的不知道如何进一步解释这个问题,但如果你需要我,我可以尝试。

For Each itemChecked In storedAuthorsListbox.CheckedItems
Dim selectedAuthor As String = storedAuthorsListbox.SelectedItem.ToString()
Dim authorFile As String = "Authors\" & itemChecked.ToString()
Dim document As XmlReader = New XmlTextReader(authorFile)

metaInfo &= "[Author]" & vbNewLine

While (document.Read())
Dim type = document.NodeType
If (type = XmlNodeType.Element) Then
If (document.Name = "Name") Then
metaInfo &= "Name=" & document.ReadInnerXml.ToString() & vbNewLine
ElseIf (document.Name = "Website") Then
metaInfo &= "Website=" & document.ReadInnerXml.ToString() & vbNewLine
ElseIf (document.Name = "Notes") Then
metaInfo &= "Notes=" & document.ReadInnerXml.ToString() & vbNewLine
End If
End If
End While
document.Close()
Next

最佳答案

当您迭代它时,某处的某些代码正在更改storedAuthorsListbox。该代码在代码片段中不可见。请确保发布的代码没有在工作线程中运行,这是不合法的。它确实像您在工作线程中运行的代码一样嘎嘎作响。

通用解决方案是制作项目的副本并从该副本而不是控件开始工作:

    Dim copy = storedAuthorsListBox.SelectedItems.OfType(Of String)().ToList()
For Each itemchecked In copy
'' etc..
Next

如果它在工作线程中运行,则将副本传递给工作线程。

关于vb.net - 该枚举器绑定(bind)到的列表已被修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18947629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com