I know how to utilize the ConcurrentDictionary<TKey, TValue> class by using a GetOrAdd() method very nicely. Is there a similar class for a single object instead? I'd rather not create a dictionary for a single object just to get concurrency.
Right now, I'm doing the following:
return _singledict.GetOrAdd(_sync, CreateSingleItem);
It sounds like you want to have some means of accessing an existing object if it has already been constructed, and constructing a new one if it hasn't been, with the appropriate tools in place to prevent the construction of multiple objects.
This is exactly what Lazy<T> exists for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With