等到达到特定标准 [英] Wait Until Specific Criteria Met

查看:86
本文介绍了等到达到特定标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个难题,我有一段代码,想等到满足某些条件而不被阻塞,然后再继续进行下一行代码.

这是流程:

-通过串行通信发送数据包
-启动超时计时器事件
-等待直到设置接收标志< =不确定在这里要做什么.接收串行事件
-如果接收标志设置继续
-通过串行通讯发送新数据包....重新开始处理.

在超时计时器事件中,将基本上重新发送数据.我的问题是,在移至下一行代码之前,如何等待直到设置了特定标志.
我所读到的Application.Doevents是执行此操作的非常不好的方法.

Hi I have a bit of a conundrum, I have a piece of code and would like to wait until certain criteria is met, without blocking, before moving on to the next line of code.

Here is the flow :

-Send packet over serial comms
-Start Timeout Timer Event
-Wait until receive flag is set <=not sure what to do here .Receive Serial Event
-If receive flag set move on
-Send New packet over Serial comms .... starts process over again.

In the timeout timer event, will basically resend the data. My question is, how do I wait until the specific flag is set, BEFORE moving to the next line of code.
Application.Doevents from what I have read is a very bad way of performing this.

推荐答案

Application.DoEvents是执行此操作的不好方法,是的.

活动是您的最佳选择.它们不必只是现有的控制事件,您的表单(或任何其他类)可以创建,处理和发出自己的事件.处理SerialPort.DataReceived,并在收到正确的数据后,通过发信号通知自己的事件将其传输到其他代码.您的事件处理程序将继续并为下一位做好准备.
Application.DoEvents is a bad way to do it, yes.

Events are you way to go. They do not have to be just the existing control events, your form (or any other class) can create, handle and signal its own events. Handle the SerialPort.DataReceived and when the right data has been received, transfer to your other code by signalling an event of your own. Your event handler than continues and prepares for the next bit.


这篇关于等到达到特定标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆