本文主要是介绍ConcurrentDictionaryHelper 字典安全 ConcurrentDictionary与Dictionary,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Imports System.Collections.Concurrent
Imports System.Runtime.CompilerServicesPublic Module ConcurrentDictionaryHelper''' <summary>''' 添加数据''' </summary>''' <typeparam name="TKey"></typeparam>''' <typeparam name="TValue"></typeparam>''' <param name="csConcurrentDictionary"></param>''' <param name="key"></param>''' <param name="value"></param>''' <returns></returns><Extension>Public Function Add(Of TKey, TValue)(ByVal csConcurrentDictionary As ConcurrentDictionary(Of TKey, TValue), key As TKey, value As TValue) As BooleanWhile Not csConcurrentDictionary.TryAdd(key, value)Threading.Thread.Sleep(1)End WhileReturn TrueEnd Function''' <summary>''' 移除数据''' </summary>''' <typeparam name="TKey"></typeparam>''' <typeparam name="TValue"></typeparam>''' <param name="csConcurrentDictionary"></param>''' <param name="key"></param>''' <param name="value"></param>''' <returns></returns><Extension>Public Function Remove(Of TKey, TValue)(ByVal csConcurrentDictionary As ConcurrentDictionary(Of TKey, TValue), key As TKey, value As TValue) As TValueWhile Not csConcurrentDictionary.TryRemove(key, value)Threading.Thread.Sleep(1)End WhileReturn valueEnd Function
End Module
这篇关于ConcurrentDictionaryHelper 字典安全 ConcurrentDictionary与Dictionary的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!