Skip to main content

All Questions

2 votes
0 answers
265 views

How to use Lazy<T>(Func<T> valueFactory) in a way that if init fails It should not use cached exception and should not run multiple threads for init? [duplicate]

How to use Lazy(Func<T> valueFactory) of C# in such a way that, if initialization fails, it should not use cached Exception and at the same time it should not run multiple threads for ...
usFarswan's user avatar
  • 193
1 vote
1 answer
371 views

Update method on ConcurrentDictionary implemented with Lazy<T> does not work

As described in this blog article, I used the Lazy<T> class to make my ConcurrentDictionary thread-safe. I created a new class called LazyConcurrentDictionary<TKey, TValue> which stores a ...
Pete Hilde's user avatar
1 vote
1 answer
1k views

Does C# lock object require lazy initialization

I may be missing some blindingly obvious documentation somewhere, but is static readonly member variable guaranteed to be initialized properly for use as a lock object? In short, I have a library ...
ShuberFu's user avatar
  • 709
0 votes
1 answer
1k views

C# using Lazy Initialization and lock together

I want some of my objects lazy initialized like: private static Lazy<MappingEngine> engine = new Lazy<MappingEngine>(() => { return new MappingEngine(); }) And I don't want ...
yakya's user avatar
  • 5,240
0 votes
2 answers
130 views

assign value to attribute in other thread

I want to assign value to att = 5 in thread t. In the main thread, I want to check if att has been assigned to 5 yet When I run the void check(), the output is always 3. Why is this? class Program ...
Fish's user avatar
  • 165