Answer the question
In order to leave comments, you need to log in
Serialization crashes while running in a parallel thread?
private void receiving()
{
while (isRecieving)
{
try {
byte[] bytes = new byte[4];
_socket.Receive(bytes);
int sizeForBuffer = BitConverter.ToInt32(bytes, 0);
bytes = new byte[sizeForBuffer];
while (sizeForBuffer != _socket.Receive(bytes)) ;
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream(bytes))
{
Message message = (Message)bf.Deserialize(ms);
_history.Add(message);
}
}
catch(System.Runtime.Serialization.SerializationException e)
{
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question