小编use*_*208的帖子

这个简单的VB.Net类线程安全吗?如果没有,我该如何改进呢?

Option Strict On

Public Class UtilityClass
  Private Shared _MyVar As String

  Public Shared ReadOnly Property MyVar() As String
    Get
      If String.IsNullOrEmpty(_MyVar) Then
        _MyVar = System.Guid.NewGuid.ToString()
      End If
      Return _MyVar
    End Get
  End Property

  Public Shared Sub SaveValue(ByVal newValue As String)
    _MyVar = newValue
  End Sub

End Class
Run Code Online (Sandbox Code Playgroud)

vb.net thread-safety

3
推荐指数
1
解决办法
4471
查看次数

使用 VB.Net Parallel.ForEach 和 ConcurrentDictionary 的正确语法是什么?

我很难使用 Parallel.ForEach 和 ConcurrentDictionary 获得正确的语法。下面 Parallel.ForEach 的正确语法是什么?

Dim ServerList as New ConcurrentDictionary(Of Integer, Server)
Dim NetworkStatusList as New ConcurrentDictionary(Of Integer, NetworkStatus)

... (Fill the ServerList with several Server class objects)

'Determine if each server is online or offline.  Each call takes a while...
Parallel.ForEach(Of Server, ServerList, Sub(myServer)
        Dim myNetworkStatus as NetworkStatus = GetNetworkStatus(myServer)
        NetworkStatusList.TryAdd(myServer.ID, myNetworkStatus)
    End Sub

... (Output the list of server status to the console or whatever)
Run Code Online (Sandbox Code Playgroud)

vb.net parallel-processing parallel.foreach

3
推荐指数
1
解决办法
1万
查看次数