Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Static class accessed from many threads of different types

Posted on 2006-10-30
6
Medium Priority
?
237 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

664 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