Solved

Dictionary and a struct

Posted on 2013-01-16
4
480 Views
Last Modified: 2013-01-16
hi -- I'm using C# and VS2010 with .net 4.
i have a dictionary that i use to keep state information in my program. the value part of the key value pair is a struct (called "node"). it seems that i can only update "node" as a single entity rather than updating individual elements when i have fresh data. i have the additional problem of the data coming from two different threads. i set up the dictionary as static and use flags to protect the write operation. but every now and then (every couple hours) i get an enumeration error, which i suspect is related to the update process.
is there a better approach?
thanks,
0
Comment
Question by:jdcoburn
4 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 167 total points
ID: 38783859
Why don't you use the ConcurrentDictionary class?
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 167 total points
ID: 38784128
"it seems that i can only update "node" as a single entity rather than updating individual elements when i have fresh data."

Switch from a struct to a class.
0
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 166 total points
ID: 38784277
About structs, many people make the same mistake by forgetting that structures are value type. See more details here, e.g.:

http://stackoverflow.com/questions/7126318/how-do-you-assign-values-to-structure-elements-in-a-list-in-vb-net


Use class instead.

ConcurrentDictionary should be a good solution but I have a feeling that something else happens.
0
 

Author Closing Comment

by:jdcoburn
ID: 38785087
thanks. all the solutions added value in different ways.<br />Jim
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now