Private Queue queueTCPCacheReceived;
Private Thread threadTCPCacheReceived;
The static System. When the Timer Timer2;
Private void ReceiveInformation2 (Object state)//timer is used to receive data
{
Try
{
Byte [] readBuffer=new byte [the sock ReceiveBufferSize];
Int count=the sock. The Receive (readBuffer);
The lock (queueTCPCacheReceived. SyncRoot)
{
for (int i=0; i
{
QueueTCPCacheReceived. The Enqueue (readBuffer [I]);
}
}
}
The catch (Exception ex)
{
String EM=ErrorMessage (ex);
Timer1. Enabled=false;//UI stop update
Timer2. Change (Timeout. Infinite, Timeout. Infinite);
The sock. The Close ();
MessageBox. Show (EM, "error");
return;
}
}
Timer2. Change (0, the Timeout. Infinite);
}
Private void ThreadTCPCacheReceivedFunction ()
{
List
ListData=https://bbs.csdn.net/topics/new List ();
While (the sock!=null & amp; & The sock. Connected)
{
Int cacheLength=queueTCPCacheReceived. Count;
Console. WriteLine (cacheLength. ToString ());
If (cacheLength & gt; 0)
{
The lock (queueTCPCacheReceived. SyncRoot)
{
for (int i=0; i {
If (listData. Count==0)
{
If ((byte) queueTCPCacheReceived. Dequeue ()==0 x55 & amp; & (byte) queueTCPCacheReceived. Dequeue ()==0 x00)
{
X55 listData. Add (0);
ListData. Add (0 x00);
}
}
Else if (listData. Count & gt; 0)
{
ListData. Add ((byte) queueTCPCacheReceived. Dequeue ());
}
If (listData. Count==896)
{
The lock (queueTCPCacheReceived. SyncRoot)
{
Byte [] byteData=(https://bbs.csdn.net/topics/listData.ToArray);
If (byteData [0]==85 & amp; & ByteData [895]==238)/validation/fore and aft
{
If (nlink_linktrack_anchor_frame0. UnpackAnchorFrame0Data (byteData, byteData. Length))
{
ErrorCount=0;
}
}
}
ListData. The Clear ();
}
}
}
}
}
QueueTCPCacheReceived. The Clear ();
} CodePudding user response:
When you receive and handle hasn't returned yet, so...
CodePudding user response: