我正在修改C#中的一个旧的大型(未记录)程序,该程序使用API在串行总线上进行通信。触发代码的其他部分以继续(C#)
有没有让OnIndication触发SendRepeatRequest继续的方法? 我想避免轮询等待Xms的国旗,因为响应时间差异很大,我需要快速响应。
//Pseudocode
public void SendRepeatRequest(int X)
{
SendToAPI();
// Wait until API responds, usually a few ms but can take 1-2min
// loop X times
}
//this is activated by the API response
public void OnIndication()
{
// Handle request from API...
// Tell SendRepeatRequest to continue
}
对于如何做到这一点,您有什么建议吗? 谢谢!
'OnIndication'是否在不同于'SendRepeatRequest'的线程上运行? – wdosanjos
尽我所知,他们在同一个线程中运行。 – Fousk
因此,可能你需要做的就是在OnIndication中设置一个标志,然后在SendRepeatRequest等待循环中测试该标志。 – wdosanjos