主要问题是:如何在后台(类似于BackgroundWorker的)几个线程运行中TestingButton_Click的代码,所以我将能够:
1.获取所有的原始数据的方法
2 。同时取消所有线程的测试
3.报告进度
4.将所有结果表检索到主线程。在后台运行并行
下面的代码是内TestingButton_Click
List<Thread> threads = new List<Thread>();
//Testing for each pair
foreach (InterfaceWithClassName aCompound in Group1)
{
foreach (InterfaceWithClassName bCompound in Group2)
{
InstancePair pair = new InstancePair();
//some code
if (testModeParallel)
{
Thread thr = new Thread(TestPairParallel);
thr.Start(pair);
threads.Add(thr);
}
else
{
Thread thr = new Thread(TestPairSerial);
thr.Start(pair);
threads.Add(thr);
}
}
}
while (true)
{
int i = 0;
foreach (Thread thread in threads)
{
if (thread.IsAlive)
break;
i++;
}
if (i == threads.Count)
break;
Thread.Sleep(1000);
}
pairsResultsDataGrid.ItemsSource = tab.DefaultView
用户能够选择什么化合物每次我有不同的数字对测试的时间来测试等等。 我对不同的方法TestPairSerial()和TestPairParallel()以防万一。
TestPairSerial()结构是
do
{
do
{
} while (isSetbCompaundParams);
} while (isSetaCompaundParams);
//filling up results into tables (main window variables) later to be connected to DataGrids
TestPairParallel()与InfinitePartitioner实现并采用类似的结构只能用Parallel.ForEach(新InfinitePartitioner(),...
谢谢您的帮助。
你的问题到底是什么。你的第一句话没有意义。提出一个问题。我建议您丢失背景信息,因为它与您当前的问题无关。 – 2011-12-14 17:09:25
查看[任务](http://msdn.microsoft.com/en-us/library/dd537609.aspx)类 – oleksii 2011-12-14 17:17:12
请选择一个问题,然后仅发布与该问题相关的信息。 – Gabe 2011-12-14 17:17:32