(100分求解C#怪问题,马上解决马上给分)
在我代码中,下面是网络部分m_Socket的发送消息,然后再接收网络返回的消息 对比后,如果发送的消息和返回的消息相同就确认发送成功
public void SendConfigCommand(string strCommand)
{
byte[] receivedBuffer = new byte[1024];
if (m_Socket.Connected)
{
int receivedLength1 = 0;
string strCommandData = "S|M|" + strCommand +"|";
byte[] bufferToSend = Encoding.GetEncoding("gb2312").GetBytes(strCommandData);
m_Socket.Send(bufferToSend);
Thread.Sleep(TimeToDelay);//TimeToDelay = 800
receivedLength1 = m_Socket.Receive(receivedBuffer);
Thread.Sleep(TimeToDelay);
string Message1= Encoding.GetEncoding("gb2312").GetString(receivedBuffer);//12-16
string d = "S|M|" + strCommand + "|";
Console.WriteLine(d.ToString() + ":"+ Message1);
//if (Message1.ToString() != d.ToString())
if (Message1!= strCommandData)
{
Console.WriteLine(" Message1 !=strCommandData");
// throw new DeviceNotReadyException("设备正忙!");
}
else
{
Console.WriteLine(" Message1==strCommandData");
}
Console.WriteLine("over");
}
为什么只要有"string Message1= Encoding.GetEncoding("gb2312").GetString(receivedBuffer);//12-16"后,程序只执行到“Console.WriteLine(d.ToString() + ":"+ Message1);” 再往下的都不会执行了。
为什么啊,我那下面的代码不可能有误的,但是我把"string Message1= Encoding.GetEncoding("gb2312").GetString(receivedBuffer);//"和它相应的代码去掉后,程序就可以执行完毕!
------解决方案--------------------
怎么判断没有执行的?是看到后面没有输出了吗?
把断点设置在Console.WriteLine(d.ToString() + ":"+ Message1); 位置,跟踪一下吧
我估计是Message1里面内容输出来导致后面没有显示的。
------解决方案--------------------
加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗加断点调试过了吗