void _listener_NewAlertClient(AlertListener sender, AlertClient alertClient) { Action action = () => { var checkClient = _manager.Clients.Where(i => i.IP.Split(':').First() == alertClient.IP.Split(':').First()).ToArray(); if (checkClient.Count() > 0) { checkClient[0].Close(); _manager.Remove(checkClient[0]); } else { txtMsg.AppendText(string.Format("{0} New Client: {1} {2}\r\n", DateTime.Now.ToString("MM-dd HH:mm"), alertClient.IP, alertClient.Location)); } _manager.Add(alertClient); alertClient.getClients(_manager); }; this.BeginInvoke(action); //當每次發生RawDataReceived事件時,即呼叫alertClient_DataReceived()方法 //alertClient.RawDataReceived += alertClient_DataReceived; alertClient.ReadyAckReceived += alertClient_ReadyAckReceived; //alertClient.ClientMsgReceived += alertClient_ClientMsgReceived; alertClient.HeartBeatReceived += alertClient_HeartBeatReceived; alertClient.TalkReceived += alertClient_TalkReceived; //alertClient.AlarmAckReceived += alertClient_AlarmAckReceived; alertClient.ServiceReadyReceived += alertClient_ServiceReadyReceived; alertClient.ServiceAlertReceived += alertClient_ServiceAlertReceived; alertClient.ServiceClose += alertClient_ServiceClose; }
void _listener_NewAlertClient(AlertListener sender, AlertClient alertClient) { Action action = () => { txtMsg.AppendText(string.Format("{0} New Client: {1}\r\n", DateTime.Now.ToString("MM-dd HH:mm"), alertClient.IP)); _manager.Add(alertClient); alertClient.getClients(_manager); }; this.BeginInvoke(action); //當每次發生RawDataReceived事件時,即呼叫alertClient_DataReceived()方法 alertClient.RawDataReceived += alertClient_DataReceived; alertClient.ReadyAckReceived += alertClient_ReadyAckReceived; //alertClient.ClientMsgReceived += alertClient_ClientMsgReceived; alertClient.TalkReceived += alertClient_TalkReceived; //alertClient.AlarmAckReceived += alertClient_AlarmAckReceived; alertClient.ServiceReadyReceived += alertClient_ServiceReadyReceived; alertClient.ServiceAlertReceived += alertClient_ServiceAlertReceived; alertClient.ServiceClose += alertClient_ServiceClose; }