我有一些方法可以发出几个网络请求。如果第一个请求满足特定条件,则该方法应立即返回结果,以便过程继续进行。但是,该方法应该继续进行下去。
这是主循环:
await Task.Run(() =>
{
while (true)
{
var data = MakeRequest(worker1);
if (worker2 != null)
data = MakeRequest(worker2);
ProcessData(data);
}
});
private SomeData MakeRequest(Worker worker)
{
//Make first request
//If results meet specific condition, return them at this point
//Second request must always be executed
}
是否有可能返回到main方法,以便worker2
可以发出请求,而对MakeRequest
的{{1}}调用仍然执行,但此后仍然执行?