使用多线程并行执行可以大大提高程序处理速度,但多个事务线程执行完毕后如何通知用户呢?
可以使用Join将多个事务线程合并到主线程中,事务线程执行完毕后主线程才可以继续执行。代码如下:
for
(
int
i
=
0
; i
<
matchCollection.Count; i
++
)
... {
//Start new thread
thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ThreadMethod));
thread.Start(remotingUrl);
threadList.Add(thread);
}
foreach (System.Threading.Thread Thread in threadList)
... {
Thread.Join();
}
... {
//Start new thread
thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ThreadMethod));
thread.Start(remotingUrl);
threadList.Add(thread);
}
foreach (System.Threading.Thread Thread in threadList)
... {
Thread.Join();
}