private void AlternetUnit_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { MRP.Focus(); } }
private void NormalizeThePackets() { if (svr == null) { return; } while (svr.IsListening) { //Debug.WriteLine("Before AutoEvent"); autoEvent.WaitOne(10000);//wait at mutex until signal, and drop through every 10 seconds if something strange happens //Debug.WriteLine("After AutoEvent"); /**********************************************/ lock (dClientRawPacketList)//http://www.albahari.com/threading/part2.aspx#_Locking { foreach (MotherOfRawPackets MRP in dClientRawPacketList.Values) { if (MRP.GetItemCount.Equals(0)) { continue; } try { byte[] packetplayground = new byte[11264];//good for 10 full packets(10240) + 1 remainder(1024) RawPackets rp; int actualPackets = 0; while (true) { if (MRP.GetItemCount == 0) { break; } int holdLen = 0; if (MRP.bytesRemaining > 0) { Copy(MRP.Remainder, 0, packetplayground, 0, MRP.bytesRemaining); } holdLen = MRP.bytesRemaining; for (int i = 0; i < 10; i++) //only go through a max of 10 times so there will be room for any remainder { rp = MRP.GetTopItem; //dequeue Copy(rp.dataChunk, 0, packetplayground, holdLen, rp.iChunkLen); holdLen += rp.iChunkLen; if (MRP.GetItemCount.Equals(0))//make sure there is more in the list befor continuing { break; } } actualPackets = 0; #region PACKET_SIZE 1024 if (holdLen >= 1024)//make sure we have at least one packet in there { actualPackets = holdLen / 1024; MRP.bytesRemaining = holdLen - (actualPackets * 1024); for (int i = 0; i < actualPackets; i++) { byte[] tmpByteArr = new byte[1024]; Copy(packetplayground, i * 1024, tmpByteArr, 0, 1024); lock (FullPacketList) FullPacketList.Enqueue(new FullPacket(MRP.iListClientID, tmpByteArr)); } } else { MRP.bytesRemaining = holdLen; } //hang onto the remainder Copy(packetplayground, actualPackets * 1024, MRP.Remainder, 0, MRP.bytesRemaining); #endregion if (FullPacketList.Count > 0) { autoEvent2.Set(); } //Call_ProcessRecievedData_FromThread(); }//end of while(true) } catch (Exception ex) { MRP.ClearList();//pe 03-20-2013 string msg = (ex.InnerException == null) ? ex.Message : ex.InnerException.Message; OnCommunications("EXCEPTION in NormalizeThePackets - " + msg, INK.CLR_RED); } } //end of foreach (dClientRawPacketList) } //end of lock /**********************************************/ if (ServerIsExiting) { break; } }//Endof of while(svr.IsListening) Debug.WriteLine("Exiting the packet normalizer"); OnCommunications("Exiting the packet normalizer", INK.CLR_RED); }