c# - 如何等待另一个类中的某个操作开始 c# 中的下一个操作?
问题描述
我知道你不明白问题的标题。让我告诉你整个场景。
我有一个名为处理器的类。处理器可以根据某些条件获取可通知的步骤或向其他应用程序 API 发送通知。如下所示:
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,因为数据库中没有设置记录。如何克服这种情况。我无法锁定它,因为许多客户都在使用它。
解决方案
推荐阅读
- html - 使用 rvest 包中的 html_nodes 时出错
- ruby - 输入没有输入作为有效的布尔值
- android - ZXing 库 - 输出结果
- slurm - slurm:如何防止工作信息被删除?
- javascript - 如何选择具有相同锚文本和href值的链接
- spring-boot - 将 Gradle 属性注入 Spring Boot application.yml,在 IntelliJ IDEA 中不起作用
- c# - 适配其他模型后缺少映射模型
- reactjs - MapActionToProps 未更新商店
- javascript - 在客户端保存 Javascript FormData() 对象
- angular - 如何通过从其他对象标签获取引用来映射模板中的值?