弄了半天也不知道哪里错了问题,看一吧
void ReceiveMsg(Object objSocket)
{
Socket socketRec = objSocket as Socket;
while (true)
{
byte[] bytes = new byte[1024 * 1024];
int len = socketRec.Receive(bytes);
if (bytes[0] == 0)
{
string message = System.Text.Encoding.UTF8.GetString(bytes, 0, len);
ShowMsg(message);
}
else if (bytes[0]==1)
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string savePath = sfd.FileName;
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
fs.Write(bytes, 1, len - 1);
ShowMsg("文件保存完毕" + savePath);
}
}
MessageBox.Show("dd");
}
}
}
当程序运行到这段代码 if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
的时候应该弹出一个保存文件的窗口,可它弹出了主程序窗口,而且我为了验证这段代码后面的程序是否被运行到,所在后面加了一段 MessageBox.Show("dd");
结果也没有运行到,为啥这样呢 |