このコードvozhusで、彼は着実に、そして急速に働いていたのです。しかし、それをスピードアップするように見えることはできません。遅いです...ThreadPoolを使用した最適化プログラム。 C#
for (int jrCnt = rCnt; jrCnt <= arrayTable.GetUpperBound(0); jrCnt++)
{
var prcI = new Price();
/* here is the code search and add data to prcI */
if ((!string.IsNullOrEmpty(prcI.name)) && (prcI.prc != 0))
{ // function add
/* adding more information to prcI */
ThreadPool.QueueUserWorkItem(delegate
{
if (!Accessor.AddProductUpdateProduct(prcI)) _updateCounter++;
_countadd++;
}); // I put the longest function in the streams
}
}
ここでは関数を呼び出します。スレッドプールであっても、長い時間実行されます。
public static bool AddProductUpdateProduct(Price price)
{
using (var db = new PriceDataContext())
{
var matchedprod =
db.Price.Where(x => x.name == price.name && x.company == price.company && x.date != price.date);
if (matchedprod.Select(x=>x).Count() > 1)
{
db.Price.DeleteOnSubmit(matchedprod.First());
db.SubmitChanges();
}
var matchedproduct = matchedprod.SingleOrDefault();
if (matchedproduct != null)
{
matchedproduct.date = price.date;
matchedproduct.prc = price.prc;
db.SubmitChanges();
return false;
}
}
/*here the code to add the product to the database.*/
return true;
}
スレッドプールで作業をスピードアップする方法を教えてください。
それはあなたがあなたのコードで何をしようとしている本当に何ですか?まず、いくつかの項目のデータコンテキストを照会します。 _返されたアイテム数が1より大きい場合は、データコンテキスト_again_を照会して最初のアイテムを取得します。その後、元のクエリで 'SingleOrDefault()'を実行して何かするのですか?これはまったく意味がありません...まず最初に、同じクエリを2回実行するのはなぜですか?第2に、あなたが最初のif文を入力すると、2番目のif文を入力することはありません...そして、 'matchedprod.Count()'が> 2の場合はどうなりますか?あなたは1つのアイテムだけを削除しますか?非常に多くの質問... – Nailuj