var StartTime = DateTime.Now; IList listProduct = bll.GetAllInfoByGIA();
int succNum;
var count = listProduct.Count / 5;
var num1 = 0;
System.Threading.Thread thread1 = new System.Threading.Thread(delegate()
{
//执行抓取方法;
for (int i = 0; i < count; i++)
{
num1 += GatherGIA(listProduct[i]);
} });
thread1.Start();
var num2 = 0;
System.Threading.Thread thread2 = new System.Threading.Thread(delegate()
{
//执行抓取方法;
for (int i = count; i < 2 * count; i++)
{
num2 += GatherGIA(listProduct[i]);
}
});
thread2.Start();
var num3 = 0;
System.Threading.Thread thread3 = new System.Threading.Thread(delegate()
{
//执行抓取方法;
for (int i = 2 * count; i < 3 * count; i++)
{
num3 += GatherGIA(listProduct[i]);
}
});
thread3.Start();
var num4 = 0;
System.Threading.Thread thread4 = new System.Threading.Thread(delegate()
{
//执行抓取方法;
for (int i = 3 * count; i < 4 * count; i++)
{
num4 += GatherGIA(listProduct[i]);
}
});
thread4.Start();
var num5 = 0;
System.Threading.Thread thread5 = new System.Threading.Thread(delegate()
{
//执行抓取方法;
for (int i = 4 * count; i < listProduct.Count; i++)
{
num5 += GatherGIA(listProduct[i]);
}
});
thread5.Start();
while (true)
{
if (thread1.ThreadState != System.Threading.ThreadState.Stopped) continue;
if (thread2.ThreadState != System.Threading.ThreadState.Stopped) continue;
if (thread3.ThreadState != System.Threading.ThreadState.Stopped) continue;
if (thread4.ThreadState != System.Threading.ThreadState.Stopped) continue;
if (thread5.ThreadState != System.Threading.ThreadState.Stopped) continue;
break;
}
thread1.Abort();
thread2.Abort();
thread3.Abort();
thread4.Abort();
thread5.Abort();
var EndTime = DateTime.Now;
succNum = num1 + num2 + num3 + num4 + num5;
string msg = string.Format("共有{0}颗GIA钻石,成功更新{1}颗GIA钻石参数,本次抓取总耗费{2}",
listProduct.Count.ToString(), succNum.ToString(), EndTime - StartTime);
this.lblGiaMsg.Text = msg;
private delegate void GatherDelegate();
private Object lockObj = new object(); public void Main()
{
DateTime StartTime = DateTime.Now; IList listProduct = new List<String>();
int succNum;
Int32 count = listProduct.Count / 5;
Int32 num1 = 0; GatherDelegate delegate1 = delegate()
{
//执行抓取方法;
for (int i = 0; i < count; i++)
{
lock (lockObj)
{
num1 += 1;
}
} }; IAsyncResult result1 = delegate1.BeginInvoke(null, null);
delegate1.EndInvoke(result1);
}