// 设备启动事件
public event EventHandler<StartArgs> EventStart;
public class StartArgs : EventArgs { /* 空 */ } // 设备停止事件
public event EventHandler<StopArgs> EventStop;
public class StopArgs : EventArgs { /* 空 */ }
因所需信息均可从 sender 获取,故如此,不知妥否。
public event EventHandler<StartArgs> EventStart;
public class StartArgs : EventArgs { /* 空 */ } // 设备停止事件
public event EventHandler<StopArgs> EventStop;
public class StopArgs : EventArgs { /* 空 */ }
因所需信息均可从 sender 获取,故如此,不知妥否。
解决方案 »
- C# TCP 发送与接收 遇到难题了!请高手解答
- c# 接口问题
- 老人帮我看看这几本c#那个好
- [WinF]Propertygrid 如何实现更改对象的名称"(Name)"属性
- 掌风贴 请不要点
- 拖动窗体MOUSEUP怎么写,用什么方法?
- IPostBackEventHandler RaisePostBackEvent eventArgument 高手回答
- 求救!一个关于fckeditor的问题
- 最后的40分了,用WINFROM模拟浏览器登陆ASPX网站(在线等答案)?
- WPF怎么调用样式里的动画 在线等待 高分跪求
- 问大家一个关于 comboBox的下拉列表的问题 高分求解 谢谢了
- 寻求多普达C720w手机的WM系统,要求能完全支持.NET2.0
顺便,EventHandler<T> 会自己检查空值吗,if (EventStart != null) EventStart(this, null); 有无必要?
没有必要EventStart(this, new StartArgs())
也没有必要声明2个参数类
更没必要if (EventStart != null)
using System.Collections.Generic;
using System.Linq;
using System.Text;class MyT
{
public event EventHandler<StartEventArgs> Started;
public class StartEventArgs : EventArgs { }
public void Start()
{
Console.WriteLine("MyT Start!");
Started(this, null); // 直接来试试
}
}namespace test5
{
class Program
{
static void Fun1(object sender, EventArgs e)
{
Console.WriteLine("Fun1");
}
static void Main(string[] args)
{
MyT myt = new MyT();
//myt.Started += Fun1;
myt.Start();
}
}
}还真的有异常,未处理的异常: System.NullReferenceException: 未将对象引用设置到对象的实例。
在 MyT.Start() 位置 D:\test5\Program.cs:行号 13
在 test5.Program.Main(String[] args) 位置 D:\test5\Program.cs:行号 29