简体   繁体   English

按顺序运行任务

[英]Run tasks sequentially

I have five windows services. 我有五个Windows服务。 I run the services sequentially. 我按顺序运行服务。

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
}

For some reason, I want to use task, the code is: 由于某种原因,我想使用任务,代码为:

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(); ... }
});

Is that okay? 这样可以吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM