问题描述
我使用 Parallel.ForEach 从字符串列表构建对象列表。这可以是 100000+ 个字符串。在构建最后几个对象之前,它可以快速而完美地工作。在 Parallel.ForEach 结束之前,循环冻结。当我为每个循环使用法线时,我没有这个问题。我也没有得到任何异常,我也没有遇到任何断点。
这是我的代码
Parallel.ForEach(files,Sub(currentFile As String)
Try
If Not currentFile.tochararray.First = "~" Then
Dim baseFile As New BaseFile(currentFile,Path.GetDirectoryName(currentFile))
If Not baseFile.SWDocMGrdocument.FileCorrupt Then
retVal.Add(baseFile)
Else
Debug.WriteLine($"Corrupt file {baseFile.FullFileName} skipped.")
End If
fileInfoWindow.Invoke(Sub()
fileInfoWindow.SetFileName(currentFile)
End Sub)
End If
Catch ex As Exception
Debug.WriteLine($"Error: {ex.Message}")
End Try
End Sub)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)