Solved

Static class accessed from many threads of different types

Posted on 2006-10-30
6
236 Views
Last Modified: 2010-04-16
I have one single datatable object in a static class.

i want multiple threads of different classes themselves to be able to access this datatable through the static classe's single public static property.

i dont think reads are a problem(correct me if I am wrong)
but I am concerned about writes

if it were threads all of the same class type accessing it i could use monitor.enter and monitor.exit
but unfortunatly the threads come from different classes

solutions please?
0
Comment
Question by:joshuadavidlee
[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
  • 2
6 Comments
 

Author Comment

by:joshuadavidlee
ID: 17839035
is there soemthing i could write in the static class that would save me having to write anything in the thread classes
0
 
LVL 10

Expert Comment

by:NetworkArchitek
ID: 17839075
Use the lock keyword. You could have the database class use the lock. That's one way to do it.
0
 

Author Comment

by:joshuadavidlee
ID: 17839081
code snippet please?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:joshuadavidlee
ID: 17839104
for example how do i say

lock(this)

when its a static class and "this" is not allowed
0
 
LVL 10

Accepted Solution

by:
NetworkArchitek earned 500 total points
ID: 17839213
No, do this.

Create a static variable

private static myLock = new Object();


Then where it is potentially dangerous do:

lock(myLock)
{

// code

}
0
 

Author Comment

by:joshuadavidlee
ID: 17839220
yes i just found that solution on msdn thanks !!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

615 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