Hello there stackoverflow! I'll just deduct the following: I have a server / client program that is using TCP and I have a problem in the queue to use to read the packet. This packet is read once, it is pressed into the queue, and if the program is not busy dealing with the packet it must handle it and it has to be removed from the queue.
Here is the code to attach the data:
If ReadIndex = ReadBuffer.Length then SyncLock ReadQueue ReadQueue.Enqueue (ReadBuffer) termination SyncLock File.WriteAllBytes (Application. StartupPath & amp; "\ Test \" & amp; & amp; ".bin", ReadBuffer) I +++ processing then (2) processing again (2) this is true = if not ThreadPool.QueueUserWorkItem (AddressOf HandleReadQueue ) Then HandleReadQueue () is the other end of the tip
Note that I am writing all the packets to each file myself (this is for debugging purposes) Use pool to handle readqueue on a separate thread
and the method to deal with the queue is:.
Private Sub HandleReadQueue () Dim Data Byte () SyncLock ReadQueue Data = ReadQueue.Dequeue () End SyncLock File.WriteAllBytes (Application.StartupPath & "TestReadQueue \" & Y and amp; ".bin", the data) Y + = 1 then _Parent isnot is nothing, then HandleClientReadPacket (_Parent, _Pipename, Data), otherwise End of HandleClientReadPacket (I, nothing, Data) end Sub
The files in TestReadQueue differ from people in the Test folder. I have no idea why. And I know of a fact that all the data has been received which is received in the form of data, similar to the one sent to the customer.
Here you can see that it is different:
This problem occurs when I do not use threadspool, but then when I do not need sync Can I tell anyone what is wrong?
ReadBuffer has actually been modified after its queue has been corrected, but I thought Enqueuing is by value and not reference?
Context is encrypted by by value .
Array is always the reference type, there are references to all the byte array ending in the queue. For example (C #)
var queue = new line & lt; Byte [] & gt; (); Byte [] buffer = {1}; Queue.Enqueue (buffer); Buffer [0] = 100; Var dequeued = queue.Dequeue (); Console.WriteLine (dequeued [0]); // 100
If you want a reference that is queued for being independent from the byte array that you are going to overwrite, then you have to clone it. For example in C # you can use:
queue.Enqueue ((byte []) buffer. Clone ()); Whatever castings you consider most suitable in VB - but the important part is that the array is cloned, and therefore is independent of the original array that you are still modifying. .
Comments
Post a Comment