Solved

Dictionary and a struct

Posted on 2013-01-16
4
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 75

Accepted Solution

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

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 30

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

734 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