Hi there,
I'm bugfixing someone else's code where it takes ages to return the complete dataset in the following code:
DataTable dt = someLib.GetDataTable("EXEC [dbo].[CMS_Content_GetAllContents]");
// Copy the DataTable data to list.
foreach (DataRow dr in dt.Rows)
{
ContentInfo aContentDetail = new ContentInfo(
(int)dr["ID"],
(string)dr["ContentName"],
getCategories((int)dr["ID"]),
null,
(string)dr["Publisher"],
(string)dr["Price"],
false);
contentInfoList.Add(aContentDetail); ;
}
private string getCategories(int ContentID)
{
String categories = String.Empty;
String query = String.Format("EXEC [dbo].[CMS_Content_GetContentCategories] @ID = {0}", ContentID);
DataTable dt = clsGlobal.GetDataTable(query);
foreach (DataRow dr in dt.Rows)
{
categories = String.Concat((string)dr["ShortDescription"] + ", ");
}
if (categories.EndsWith(", "))
categories = categories.TrimEnd(new char[] { ',', ' ' });
return categories;
}
It is pathetic as there are over 1,000 rows for the DataTable dt and I cannot deal with it from the store proc level!
I'm just wondering if I can bundle the call getCategories(int)
into Threadpool.QueueUserWorkItem() such that it can go parallel but dunno how to return the string back to the caller?
Or, is it a bad idea to use Threadpool because I heard that the Threadpool's workers threads are not designed for long running queries such as DB calls as the IOCompletion ports thread may not return in time hence workers are likely to get blocked because of that?
Any helps appreciated.