Solved

Static class accessed from many threads of different types

Posted on 2006-10-30
6
232 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help on C# Linq query on object 6 62
Device Location 4 29
What namespace do I need to import? 2 25
Get distinct values from excel or comm seperated file 4 23
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now