如何等待另一个类中的某个操作开始c#中的下一个操作?
我知道你不明白问题的标题。让我告诉你整个情况 我有一个名为Processor的类。处理器可以根据某些条件获取应通知的步骤或向其他应用程序API发送通知。如下所示:如何等待另一个类中的某个操作开始c#中的下一个操作?,c#,C#,我知道你不明白问题的标题。让我告诉你整个情况 我有一个名为Processor的类。处理器可以根据某些条件获取应通知的步骤或向其他应用程序API发送通知。如下所示: Method: SendOrStartProcess(Operation operation) Method Implementation: If(operation.steps.any(o=>o.canProcess)){ _service.notify(operations); //This is fine
Method: SendOrStartProcess(Operation operation)
Method Implementation:
If(operation.steps.any(o=>o.canProcess)){
_service.notify(operations); //This is fine
}
else{
var totalSteps = await _service.getAdjustableSteps(); //It returns the adjustable steps and will invoke event which is subscribed by another class named as GetAdjustableStepsEnd. It can be invoked immediately or after some time.
//Set totalSteps in operationsc.steps and save in database and that's it.
}
现在,我有了另一个名为“OperationHandler”的类,它对GetAdjustableStepsEnd事件进行了子循环
public OperationHandler(IUnityContainer container)
{
_agent.GetAdjustableStepsEnd += GetAdjustableStepsEnd ;
}
public async void GetAdjustableStepsEnd (object sender, GetAdjustableStepsEndEventArgs e)
{
// Here i will call again the above method _processor.SendOrStartProcess(e.Operations);
}
//现在的问题是,若事件在一段时间后调用,那个么就没问题了,因为同时我在数据库中设置了状态。但如果它在getAdjustableSteps之后调用,那么我再次调用SendOrStartProcess,它再次发送getAdjustableSteps,因为数据库中没有设置记录。如何克服这种情况。我无法锁定它,因为许多客户端都在使用它。所以只有在尚未将值保存到数据库时才调用SendOrStartProcess?您不能假设该值在事件发生时必须已保存吗?不。我不能,因为它可以随时调用。因此,只有在未将该值保存到数据库时,您才调用SendOrStartProcess?你不能假设该值必须在事件发生时保存吗?不。我不能,因为它可以随时调用。