我有五个Windows服务。我按顺序运行服务。
if(a_Condition)
{
services[0] = new Processing_0();
// blah blah
}
if(b_Condition)
{
service[1] = new Processing_1();
// blah blah
}
if(c_Condition)
{
service[2] = new Processing_2();
// blah blah
}
if(d_Condition)
{
service[3] = new Processing_3();
// blah blah
}
if(e_Condition)
{
service[4] = new Processing_4();
// blah blah
}
出于某种原因,我想使用任务,代码是:
Task.StartNew(() => {
if (a_Condition) { var x = new Processing_0(); ... }
})
.ContinueWith(() => {
if (b_Condition) { var x = new Processing_1(); ... }
})
.ContinueWith(() => {
if (c_Condition) { var x = new Processing_2(); ... }
})
.ContinueWith(() => {
if (d_Condition) { var x = new Processing_3(); ... }
})
.ContinueWith(() => {
if (e_Condition) { var x = new Processing_4(); ... }
});
可以吗?
答案 0 :(得分:1)
没关系!
上查看MSDN关于Continuations的文章