C# Socket 多线程问题!
启动一个线程:
CheckForIllegalCrossThreadCalls = false;
Thread th = new Thread(new ThreadStart(ReciveMessage));
th.Start();
public void ReciveMessage()
{
while (true)
{
if (client != null)
{
byte[] recvBytes = new byte[120];
bytes = client.Receive(recvBytes, recvBytes.Length, 0);
byte[] bytefour = new byte[4];
bytefour[3] = recvBytes[0];
bytefour[2] = recvBytes[1];
bytefour[1] = recvBytes[2];
bytefour[0] = recvBytes[3];
float s = BitConverter.ToSingle(bytefour, 0);
textBox1.Text += s.ToString();
textBox1.Text += " ";
}
else
{
label1.Text = "123";
}
}