Tuesday, July 30, 2013

How to limit the number of threads in C#

Agreed, limiting the Thread Number is not a really good solution.


Actually to opposite approach might be better: consider packing as much work as possible into one Query isntead of splitting it over as many Queries as possible.


The basic rules for DB access from Code:

Do as few querries as possible, pack as much work into one Query as possible, while retrieving as little data as you need. Compared to your other code DB-access is very costly and splitting them up only increases the cost.


Could it be that you ran into a Timeout or OutOfMemory Exception while doing the work in one run?


The Command Timeout can be increased:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx


While a OOM is better solved by using paging (retrieving a smaller group at once, isntead all at once or all seperately) or reducing the number of Rows retreived:


http://blogs.iis.net/webtopics/archive/2009/05/22/troubleshooting-system-outofmemoryexceptions-in-asp-net.aspx


If this is only about not locking up the UI, use one Thread to do all the rerieval work in one go.


In any case we need a lot more details about what you are doing to give any specific advice.




Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.


No comments:

Post a Comment