473,698 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

single class, hashtable, multiple threads

Hello All,

I have a single class windows service that includes a function that
runs in the ThreadPool. The class contains a hashtable which is
declared in the main thread.

What is the recommended method of updating a variable declared in the
main thread from a spawned threadpool thread ?
Thanks in advance

Feb 12 '07 #1
2 1567
You can use Hashtable.Synch ronized:

http://msdn2.microsoft.com/en-us/lib...chronized.aspx

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"hharry" wrote:
Hello All,

I have a single class windows service that includes a function that
runs in the ThreadPool. The class contains a hashtable which is
declared in the main thread.

What is the recommended method of updating a variable declared in the
main thread from a spawned threadpool thread ?
Thanks in advance

Feb 12 '07 #2
Be aware also that Hashtable.Synch ronized is not really RW safe.
It does synchronize writers, but not readers.

"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .comha scritto nel
messaggio news:09******** *************** ***********@mic rosoft.com...
You can use Hashtable.Synch ronized:

http://msdn2.microsoft.com/en-us/lib...chronized.aspx

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"hharry" wrote:
>Hello All,

I have a single class windows service that includes a function that
runs in the ThreadPool. The class contains a hashtable which is
declared in the main thread.

What is the recommended method of updating a variable declared in the
main thread from a spawned threadpool thread ?
Thanks in advance


Feb 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1756
by: M Ali | last post by:
Hi, We have a c++ application that accesses many different modules. Each of these modules is responsible for it's own serialization. We have seperate olestorages for each of the module. The main application hands over these storage pointers to each module which then do whatever-they-want to their respective storages. Everything is kept with in a single file. Seperate storages for each module help tremendously because
5
15576
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. One function of the Hashtable is to iterate through its keys, which apparently is inherently not thread-safe. Other functions of the Hashtable include adding/modifying/deleting. To solve the synchronization issues I am doing two things: 1. Lock...
33
3312
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are used before adding, removing or iterating the Hashtable. The program runs in a high workload environment. After running a few days, now it suddenly catchs this Exception when inserting a pair of key and object, stacktrace =...
2
3739
by: Paul Wu | last post by:
From what I understand, in ASP.NET, each HTTP requests is serviced by a separate thread. So if my code uses a static Class with shared members and properties, I can manage concurrent access by using something like the Monitor or ReaderWriterLock class. It is rather difficult to simulate multiple threads in a debug environment so I am hoping someone can enlighten me by telling me what happens in the following scenario? A request is made to...
6
968
by: cj | last post by:
I want to make a class that will write data to a in memory table. This class will be called by multiple threads. I'm hoping the table can stay in memory between calls and all the call by the thread will have to do is pass some data to be added to the table. Kinda like this class I have to write to a log file. Public Class MyStringLogger Private Shared m_loglock As New Object Public Shared Sub Write(ByVal fileName As String, ByVal...
10
8505
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new Hashtable()); 2. create ArrayList aList = ArrayList.Synchronized(new ArrayList()); 3. create a string sList = ""; For 1 and 2, since the list is synced, many threads can directly
2
3143
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 need to write to it, but now it occurred to me that maybe I could just lock one of the Hashtables inside without locking the entire object, but then I thought maybe some thread could instruct the outside Hashtable to remove an inside Hashtable...
35
9352
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from 500000 to 3200000 of a file whose size is say 20MB... how do i request a download which starts directly at 500000th byte... thank u cheers
4
1668
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 "row level", the whys aren't important at this time. Does this code actually do what I want? using System; using System.Collections; using System.Collections.Generic; using System.Text;
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.