/// <summary> /// 清理所有数据 /// </summary> public void Clear() { long[] keys = new long[dicPool.Count]; dicPool.Keys.CopyTo(keys, 0); RecvicePool pool = null; foreach (var key in keys) { if (dicPool.TryRemove(key, out pool)) { pool.Clear(); } } dicPool.Clear(); }
private void Pool_OnReviceData(object sender, long id, byte[] data, RecviceState state) { //一组接收完成 if (dicSucess.ContainsKey(id)) { return; } dicSucess[id] = DateTime.Now; RecvicePool pool = null; dicPool.TryRemove(id, out pool); if (OnDataReceived != null) { AsyncUdpUserToken token = new AsyncUdpUserToken(); token.Data = data; token.Remote = remote; token.Length = data.Length; Task.Factory.StartNew(() => { OnDataReceived(this, token); }); RecvicePool recvice = sender as RecvicePool; if (recvice != null) { recvice.Clear(); } recvice.OnLossData -= Pool_OnLossData; recvice.OnReviceData -= Pool_OnReviceData; //完成发送一次 LosPackage package = new LosPackage(); package.packageType = 3; package.packageID = id; Pool_OnLossData(this, remote, new LosPackage[] { package }); Console.WriteLine("sucess:" + id); } }