c# - 接口(interface)事件的实际使用

标签 c# events interface delegates

<分区>

什么是接口(interface)事件(在接口(interface)内声明事件)的强大功能的一个很好的例子?

大多数时候我只看到接口(interface)中的公共(public)抽象方法。

最佳答案

我使用事件在串行端口接收到数据时发出信号。

这是我的界面。

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; }
}

关于c# - 接口(interface)事件的实际使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1745990/

相关文章:

c# - 如何引发跨线程事件

c# - 如何使用具有可变持续时间值的 [OutputCache (Duration=2000)] 并重置服务器缓存

c# - FormClosing 需要新线程吗?

javascript - 索引文件到模块实例的交互

java - 为什么这会导致 "The field name is ambiguous"错误?

java - 银行类OOP接口(interface)决定

pointers - 接口(interface)不能调用self方法

c# - "Could not find type"在 Windows 窗体设计器中加载窗体时出错

c# - 多线程求和给出不正确的结果

c# 代码改进(数组、列表)