问题描述
您好,专家,
这是用于半自动硬件设备测试.用户将要测试的设备(被测试者")放置在设备中.
然后用户点击一个按钮.这是此上下文中的唯一按钮.它不在键盘上,而是属于设备.正在处理按钮命中,并最终将其作为事件到达应用程序.
应用程序核心是一系列任务.最简单的方法是使用诸如
Hi experts,
this is for a semi-automatic hardware device test. User places the device to be tested ("the testee") within the apparatus.
Then User hits a button. It is the only button within this context. It''s not on the keyboard but belongs to the apparatus. The button hit is being processed and finally reaches the application as an event.
The application core is a sequence of tasks. The easiest way to accomplish that would be to have some statements like
Task0();
WaitForUserButton();
Task1("Foo", "Bar");
Task2(24);
WaitForUserButton();
Task3();
有趣的部分是WaitForUserButton()
.
在执行下一条语句之前,用户必须与被测试者打交道,然后按其按钮声明该序列可以继续.
为了管理序列的连续,我使用了 System.Threading.AutoResetEvent [ ^ ]这样:
The interesting part is WaitForUserButton()
.
Prior to executing the next statement(s), User has to deal with the testee and then press his button to announce that the sequence may continue.
To manage the block-and-continue of the sequence, I used System.Threading.AutoResetEvent[^] this way:
using System.Threading;
private AutoResetEvent _autoResetEvent = new AutoResetEvent(false);
void MyBase_ExternalButtonPressed()
{
_autoResetEvent.Set();
}
private void WaitForUserButton()
{
MyBase.ExternalButtonPressed += MyBase_ExternalButtonPressed;
_autoResetEvent.WaitOne(TimeSpan.FromMilliseconds(100));
MyBase.ExternalButtonPressed -= MyBase_ExternalButtonPressed;
}
现在,我需要对具有此类事件处理程序签名的另一个事件做出反应:
Now I need to react on another event with such an event handler signature:
public delegate void ParameterPackedDelegate(int foo);
我只是不明白将该foo
值转换为WaitForSomeEvent()
.
如何将数据附加到AutoResetEvent.Set()
?
I just don''t see how to get that foo
value into WaitForSomeEvent()
.
How can I attach data to AutoResetEvent.Set()
?
推荐答案
这篇关于跨线程边界传输数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!