Sad*_*ana 2 vb.net ienumerable wcf
我无法理解这个错误的底部,因为它只发生在一个实例中,我找不到任何可能导致错误的代码.
我有一个3.5 Web服务,我从一个多线程的CAB客户端调用.我有一堆针对Web服务的单元测试(来自3.5和2.0代码),它工作正常.但是,在实际应用中,它在90%的时间内不起作用,而剩余的10%的时间,它决定工作.
代码:
Friend Function ExecuteSearch(ByVal query As String) As List(Of SomeObject)
Dim searchResults As List(of Object) = _searcher.UserSearch(query)
Return searchResults
End Function
// In Searcher
Public Function UserSearch(ByVal query As String) As List(Of SomeObject)
Return Translate(Search.GetResults(query))
End Function
// In Search
Public Function GetResults(ByVal query As String) As List(Of SomeObject)
Dim service As New FinderService.FinderService()
Dim results As New List(Of String)
Dim serviceResults As IEnumerable(Of String) = service.Search(query) // <-- ERRORS OUT HERE
results.AddRange(serviceResults)
Return results
End Function
// In the service
Public Function Search(ByVal query As String) As IEnumerable(Of String)
Initialize() // Initializes the _accounts variable
Dim results As New List(of String)
For Each account As User In _accounts
If a bunch of conditions Then
results.Add(account.Name)
End IF
End For
Return results
End Function
Run Code Online (Sandbox Code Playgroud)
断点击中了这些代码(按此顺序).出错的行在"GetResults"方法中.
任何帮助,将不胜感激.
啊,Heisenbugs:D
显然_accounts在循环期间被修改.你可以通过这样做来缓解它
For Each account As User In _accounts.ToList()
Run Code Online (Sandbox Code Playgroud)
因此创建并枚举当前_accounts的副本,而不是可能更改的实际集合
| 归档时间: |
|
| 查看次数: |
5826 次 |
| 最近记录: |