Sometimes being Lazy is a good thing(softwareblog.alcedo.com)

submitted by fredrikmorkfredrikmork(162) 4 months, 17 days ago

ConcurrentDictionary.GetOrAdd may cause unwanted side effects where the code that produces the value may be run more than once. This is a discussion of that scenario, along with a TDD-style walk-through of a solution.

3 comments |category: |Views: 192

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by dpetersondpeterson(4397) 4 months, 16 days ago 0

Very cool stuff. Alternatively, one could possibly push the value updating to the task, but this is cooler ;-)

Reply

posted by fredrikmorkfredrikmork(162) replied to dpetersondpeterson(4397), 4 months, 16 days ago 0

Thanks! In the concrete case that I had it was necessary to prevent the task to get started unless it was added to the dictionary (it performed a rather slow operation on a networked device). Or perhaps I misunderstand what you mean?

Reply

posted by dpetersondpeterson(4397) replied to fredrikmorkfredrikmork(162), 4 months, 16 days ago 0

No you understood me correctly. You're right though, in your case it wouldn't have made sense to run the task as it involved network IO. I was just speaking in the general sense. :-)

Reply

information Login or create an account to comment on this story