Hello i have a very annoying problem when trying to use a foreach loop on my hashtable, sometimes i get the same object twice, and i really can't figure out why, i hope someone can tell me what i am doing wrong
Hashtable tmp = Hashtable.Synchronized((Hashtable) mirrorContains[searchstring]);
foreach (DictionaryEntry entry in tmp)
{
new Thread(delegate() { commit(entry, searchstring); }).Start();
}
private void commit(DictionaryEntry entry, string searchstring)
{
MirrorInfo minfo = (MirrorInfo) entry.Key;
System.Console.WriteLine(minfo.Name);
}
problem is that the the dictionaryentry passed to the commit method sometimes refers to the same object, which shouldn't be possible on a synchronized hashtable, problem is the error is not very easy to reproduce as it only happens sometimes, i hope someone can tell me what i'm doing wrong
Regards
Martin
1 1123
Hello i have a very annoying problem when trying to use a foreach loop on my hashtable, sometimes i get the same object twice, and i really can't figure out why, i hope someone can tell me what i am doing wrong
Hashtable tmp = Hashtable.Synchronized((Hashtable) mirrorContains[searchstring]);
foreach (DictionaryEntry entry in tmp)
{
new Thread(delegate() { commit(entry, searchstring); }).Start();
}
private void commit(DictionaryEntry entry, string searchstring)
{
MirrorInfo minfo = (MirrorInfo) entry.Key;
System.Console.WriteLine(minfo.Name);
}
problem is that the the dictionaryentry passed to the commit method sometimes refers to the same object, which shouldn't be possible on a synchronized hashtable, problem is the error is not very easy to reproduce as it only happens sometimes, i hope someone can tell me what i'm doing wrong
Regards
Martin
Could you provide a bit more information on what the program is doing exactly?
How are threads part of it?
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Keith Langer |
last post by:
I have a hashtable which is accessed by two threads. One thread does
all writing and enumeration in the hashtable, and the other thread has
read-only access to the table directly through keys but...
|
by: Dave Kirby |
last post by:
I am working on a network management program written in python that has
multiple threads (typically 20+) spawning subprocesses which are used
to communicate with other systems on the network. This...
|
by: Cyrus |
last post by:
I have a question regarding synchronization across multiple threads for a
Hashtable. Currently I have a Threadpool that is creating worker threads
based on requests to read/write to a hashtable....
|
by: bernardpace |
last post by:
Hi,
Using the following code
Hashtable myData = Hashtable.Synchronized(new Hashtable());
Then I will be having a main thread that will write to this hashtable,
and other n threads that will...
|
by: Jeremy |
last post by:
I have a core VB service that monitors a database, and based on data in the
records will execute code to send email notifications.
Problem:
I don't want my main program code to halt and wait for...
|
by: akantrowitz |
last post by:
In csharp, what is the correct locking around reading and writing into
a hashtable. Note that the reader is not looping through the keys,
simply reading an item out with a specific key:
If i...
|
by: PAzevedo |
last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from
multiple threads, now the Hashtable object is thread safe for reading,
but not for writing, so I lock the object every time I...
|
by: Mark S. |
last post by:
Much to my surprised the code below compiled and ran. I just don't know
enough about threading to know for sure if this is too good to be true.
I'm attempting to isolate the Hashtable lock to...
|
by: Mike |
last post by:
Hi All,
I'm using vb.net as my codebehind lang. and the following code is
being executed in my aspx.vb page to stamp a DB row.
Dim oStatsInfo As New StatsInfo(CartID, Batch, Set, Num, 0, 0, 0,...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |