Click here to Skip to main content
15,897,518 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problems with generic list data structure Pin
sam L7-Jul-08 21:15
sam L7-Jul-08 21:15 
GeneralRe: Problems with generic list data structure Pin
leppie7-Jul-08 21:39
leppie7-Jul-08 21:39 
AnswerRe: Problems with generic list data structure Pin
dibya_20037-Jul-08 19:50
dibya_20037-Jul-08 19:50 
GeneralRe: Problems with generic list data structure Pin
leppie7-Jul-08 21:00
leppie7-Jul-08 21:00 
AnswerRe: Problems with generic list data structure Pin
N a v a n e e t h7-Jul-08 21:32
N a v a n e e t h7-Jul-08 21:32 
QuestionSetup and deployment for windows application Pin
vishnukamath7-Jul-08 18:03
vishnukamath7-Jul-08 18:03 
AnswerRe: Setup and deployment for windows application Pin
Rutvik Dave8-Jul-08 8:56
professionalRutvik Dave8-Jul-08 8:56 
QuestionPerformance Related bug in C# code Pin
Tina P7-Jul-08 17:56
Tina P7-Jul-08 17:56 
Hello all,

I've been assigned 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.CloseConnection);



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);

}


}

}

Please help me out here, I'm not sure what is causing this behaviour??? Is there something in the code that needs to be fixed???

I'd really appreciate it!

Thanks

Tina
AnswerRe: Performance Related bug in C# code Pin
Ashfield7-Jul-08 21:09
Ashfield7-Jul-08 21:09 
GeneralRe: Performance Related bug in C# code Pin
Tina P7-Jul-08 21:21
Tina P7-Jul-08 21:21 
AnswerRe: Performance Related bug in C# code Pin
Harvey Saayman7-Jul-08 21:20
Harvey Saayman7-Jul-08 21:20 
GeneralRe: Performance Related bug in C# code Pin
Tina P7-Jul-08 21:28
Tina P7-Jul-08 21:28 
GeneralRe: Performance Related bug in C# code Pin
Harvey Saayman7-Jul-08 21:40
Harvey Saayman7-Jul-08 21:40 
GeneralRe: Performance Related bug in C# code Pin
Ashfield7-Jul-08 22:12
Ashfield7-Jul-08 22:12 
GeneralRe: Performance Related bug in C# code Pin
mav.northwind7-Jul-08 22:33
mav.northwind7-Jul-08 22:33 
GeneralRe: Performance Related bug in C# code Pin
Ashfield7-Jul-08 22:38
Ashfield7-Jul-08 22:38 
QuestionQuery regarding IEnumerable [modified] - Stupid question Pin
dan!sh 7-Jul-08 17:55
professional dan!sh 7-Jul-08 17:55 
AnswerRe: Query regarding IEnumerable Pin
PaulLinton7-Jul-08 18:54
PaulLinton7-Jul-08 18:54 
GeneralRe: Query regarding IEnumerable Pin
dan!sh 7-Jul-08 19:06
professional dan!sh 7-Jul-08 19:06 
GeneralRe: Query regarding IEnumerable Pin
PIEBALDconsult8-Jul-08 4:29
mvePIEBALDconsult8-Jul-08 4:29 
AnswerRe: Query regarding IEnumerable Pin
PIEBALDconsult7-Jul-08 18:54
mvePIEBALDconsult7-Jul-08 18:54 
AnswerRe: Query regarding IEnumerable [modified] - Stupid question Pin
N a v a n e e t h7-Jul-08 21:34
N a v a n e e t h7-Jul-08 21:34 
QuestionIntegrate desktop application with browser??? Pin
Technobizz7-Jul-08 17:50
Technobizz7-Jul-08 17:50 
AnswerRe: Integrate desktop application with browser??? Pin
Kjetil Svendsen7-Jul-08 20:36
Kjetil Svendsen7-Jul-08 20:36 
QuestionWindows Service Question Pin
Richard Blythe7-Jul-08 17:06
Richard Blythe7-Jul-08 17:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.