在WinForms中使用backgroundworker处理带有事件的数据流
我在 C# 中遇到一些麻烦。我对 C# 事件非常陌生,因此很难想象我的问题的全局解决方案。我应该做一个 WinForm 从 LabJackDriver 收集数据并绘制图表。我已经准备好了一个图形组件,所以我的问题是如何做基础知识。
我在这里搜索一些解决方案,发现这个。我正在尝试以这种方式解决一些问题。
您能给出一些如何启动的步骤吗?我必须实现以下接口:
public interface IStream {
event StreamingDataArriveEventDelegate StreamingDataArrive;
event StreamingStateChangeEventDelegate StreamingStateChange;
void addAnalogPort(int portId);
ISensorSource getSensorSource(int portId);
void Start();
void Stop();
void Close();
}
提前致谢,
Pedro D
I having some trouble in C#. I'm very new to C# events, so it's being difficult to me visualize the global solution to my problem. I'm supposed to do a WinForm to collect data from a LabJackDriver and graph it. I have a graph component ready, so my problem is how to do the basics.
I was searching were about some solutions here and I found this. I'm trying some solution in this way.
Can you give some steps in how to start it? I must implement the fallowing interface:
public interface IStream {
event StreamingDataArriveEventDelegate StreamingDataArrive;
event StreamingStateChangeEventDelegate StreamingStateChange;
void addAnalogPort(int portId);
ISensorSource getSensorSource(int portId);
void Start();
void Stop();
void Close();
}
Thanks in advance,
Pedro D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您首先创建一个实现该接口的类,如下所示
将所有
throw new NotImplementedException();
替换为相关代码。这仍然与事件没有太大关系。我想您还需要知道如何触发事件。
使用
MyClass
时,当您需要通知用户数据已到达时,您可以像这样触发SteamingDataArrive
事件:或者无论您的委托签名是什么。
要侦听同一事件,您可以将事件订阅到处理程序
并创建处理程序,
您可能需要更改 StreamingDataEventArgs 以匹配您的委托签名。
Well you start by creating a class that implements the interface, like this
Replace all
throw new NotImplementedException();
with relevant code.This has still not much to do with events. I suppose you also need to know how to fire an event.
Withing your
MyClass
when you need to notify the user that data has arrived you fire theSteamingDataArrive
event like this:or whatever your delegate signature is.
To listen to the same event you subscribe the event to a handler
and create a handler
you might need to change
StreamingDataEventArgs
to match your delegate signature.