所以这里是交易。我有所有实现相同的对象列表interface
。让我们称之为这个列表things
。因为每个thing
in都things
实现了相同的接口,所以我知道他们有方法调用DoStuff(StuffParams stuffParams)
。我想为每个thing
异步调用此方法,并在每个完成时执行某些操作。所以要更具体一些。
public void CreateSomething(Something something)
{
ValidateSomething(something);
someDAL.AddSomething(something);
AddSomethingToMonitor(something);
var things = someService.GetThings();
// every thing in things has method DoStuff
// invoke thing.DoStuff for each thing in things and return to caller
}
// when those methods return something should happen
// but I don't know where to write that code. Inside CreateSomething or outside.
我想我应该使用 async 和 await 关键字来实现我想要的,但我不知道如何。