1、【事件处理器】订阅【自定义事件】
public void begin(string ip, string port, DataProcCallBack dataProcCallBack)
{
...
// 开启【事件拥有者】线程
Thread threadReceive = new Thread(new ThreadStart(ReceiveData));
threadReceive.IsBackground = true;
threadReceive.Start();
...
// 绑定【事件】和【事件处理器】
DataInput += dataProcCallBack;
}
2、【自定义事件】和【委托】
public delegate void DataProcCallBack();
public event DataProcCallBack DataInput;
3、【事件拥有者】触发【自定义事件】
private void ReceiveData()
{
...
if (client.Available != 0)
{
enQueue(br.ReadBytes(client.Available));
// 触发【事件】
DataInput();
}
}