实际使用界面事件 [英] Practical use of interface events

查看:159
本文介绍了实际使用界面事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是界面事件的功率(声明接口内部事件)的一个很好的例子?



大多数我所看到的内部接口唯一的公共抽象方法的时代。


解决方案

我用的事件时,一个串口接收到的数据信号。



< 。p>下面是我的界面

 公共接口ISerialPortWatcher 
{
事件的EventHandler< ReceivedDataEventArgs> ReceivedData;
事件的EventHandler StartedListening;
事件的EventHandler StoppedListening;

SerialPortSettings PortOptions {设置; }

布尔听力{搞定;组; }
无效停止();
无效的start();
}

公共类ReceivedDataEventArgs:EventArgs的
{
公共ReceivedDataEventArgs(字符串数据)
{
数据=数据;
}
公共字符串数据{搞定;私人集; }
}


What is a good example of the power of interface events (declaring events inside interface)?

Most of the times I have seen only public abstract methods inside interface.

解决方案

I used events to signal when a serial port received data.

Here is my interface.

public interface ISerialPortWatcher
{
    event EventHandler<ReceivedDataEventArgs> ReceivedData;
    event EventHandler StartedListening;
    event EventHandler StoppedListening;

    SerialPortSettings PortOptions { set; }

    bool Listening { get; set; }
    void Stop();
    void Start();
}

public class ReceivedDataEventArgs : EventArgs
{
    public ReceivedDataEventArgs(string data)
    {
        Data = data;
    }
    public string Data { get; private set; }
}

这篇关于实际使用界面事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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