Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strike>Yes</strike> You can do it like this.</p> <pre class="lang-vb prettyprint-override"><code>Dim WorkingDict As New HybridDictionary WorkingDict.Add("k1", "v1") WorkingDict.Add("k2", "v2") Parallel.ForEach(WorkingDict.Cast(Of Object), Sub(DictObject As KeyValuePair(Of String, String)) ' do something End Sub) </code></pre> <p>You need to use the <code>IEnumerable.Cast</code> operator because <code>Parallel.Foreach</code> <a href="http://blogs.msdn.com/b/pfxteam/archive/2010/03/02/9971804.aspx" rel="nofollow noreferrer">only works with generic collections</a>. <code>HybridDictionary</code> is a non-generic collection.</p> <p>But keep in mind that this is a very simple [empty] example and more complex parallel operations require many considerations such as locking shared resources etc. You could always consider using a <code>System.Collections.ConcurrentDictionary</code>, which handles locking shared resources if needed. <a href="https://stackoverflow.com/questions/7028919/concurrentdictionary-addorupdate">A SO post on this</a>. Example:</p> <pre class="lang-vb prettyprint-override"><code>Dim WorkingDict As New ConcurrentDictionary(Of String, String) ' ConcurrentDictionary has no Add operator, so to replicate it, use AddOrUpdate ' and just pass the same value whether it is being added or updating WorkingDict.AddOrUpdate("key1", "value1", Function(key, oldvalue) "value1") WorkingDict.AddOrUpdate("key2", "value2", Function(key, oldvalue) "value2") Parallel.ForEach(WorkingDict, Sub(DictObject as DictionaryEntry) ' do something End Sub) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload