DictionaryExtensionsAsThreadSafeTKey, TValue Method

Returns a LockingDictionaryTKey, TValue, which provides a thread-safe wrapper for the specified dictionary. This only means that if the members are accessed through the returned LockingDictionaryTKey, TValue, then the inner state of the wrapped dictionary remains always consistent and not that all the multi-threading concerns can be ignored.
See the Remarks section of the LockingDictionaryTKey, TValue class for details and some examples.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public static LockingDictionary<TKey, TValue> AsThreadSafe<TKey, TValue>(
	this IDictionary<TKey, TValue> dictionary
)

Parameters

dictionary  IDictionaryTKey, TValue
The dictionary to create a thread-safe wrapper for.

Type Parameters

TKey
The type of the keys in the dictionary.
TValue
The type of the values in the dictionary.

Return Value

LockingDictionaryTKey, TValue
A LockingDictionaryTKey, TValue, which provides a thread-safe wrapper for the specified dictionary.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IDictionaryTKey, TValue. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

To use a thread-safe dictionary without wrapping any IDictionaryTKey, TValue instance consider to use the ThreadSafeDictionaryTKey, TValue class instead.

For a CacheTKey, TValue instance consider to use the GetThreadSafeAccessor method instead, which does not necessarily lock the item loader delegate.

See Also