Tutorials
Resources
Forum
Interview
Jobs
Projects
Offshore Development
Silverlight Tutorials
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Revenue Sharing
|
My Profile
Sign In
Register
AdSense Revenue
Gifts
Active Members
Today
Dharmaraj
(22)
Vivek
(15)
vipul
(10)
Last 7 Days
Meetu Choudhar...
(671)
Appukuttan
(512)
Satyanarayan Su...
(464)
more...
multi-threaded windows application method, can any help me out this problem
Posted Date:
03 Jul 2008
Total Responses:
0
Posted By:
tippu
Member Level:
Bronze
Points
: 1
You have discovered a bug in a multi-threaded windows application method that serves lookup data. The method fills a static list object full of simple data objects. When only one thread hits the method the method executes rapidly. The SQL stored procedure that is returning the results is optimized and runs quickly. You can test it using a T-SQL call and it runs in less than a millisecond. When one thread accesses the method the code returns just as quickly. But when more than one thread hits the method at the same time load up of the static list object becomes slower in an exponential fashion, driving system resource usage up and taking much longer than expected. After the list runs then the usage drops again, since the method is no longer called until the application is recycled.
private static List<DataObject> _list = null;
public static List<DataObject> GetList()
{
if (_list == null)
{
_list = new List<DataObject>();
SqlDataReader reader = null;
SqlConnection connection =
new SqlConnection(ConnectionString);
SqlCommand command = null;
// Set up a new command
command = new SqlCommand("GetList", connection);
command.CommandType = CommandType.StoredProcedure;
reader =
command.ExecuteReader(CommandBehavior.CloseConnect ion);
while (reader.Read())
{
DataObject instance = new DataObject();
instance.ID = reader["ID"] != DBNull.Value &&
reader["ID"] != null ? (int)reader["ID"] : 0;
instance.Name = reader["Name"] != DBNull.Value &&
reader["Name"] != null ? (string)reader["Name"] :
string.Empty;
_list.Add(instance);
}
}
}
First, give an explanation of what is wrong and why the issue stated above is happening. Then write the code and give a detailed explanation of how you would solve this issue?
Responses
No responses found. Be the first to respond and make money from
revenue sharing program
.
Post Reply
You must
Sign In
to post a response.
Next :
Datetime
Previous :
Can any one help me out , Factory classes
Return to Discussion Forum
Post New Message
Category:
.NET
Related Messages
what is a resource file...
Horizontal Scroll Bar for a listview control
sql querry
sql querry interview question
connection string for sql , pls help
dotNet Slackers
BizTalk Adaptors
Web Design
online optimum rewards
Contact Us
Privacy Policy
Terms Of Use