程序运行过程中死机的解决方法?
时间:2008-03-13
来源:互联网
我用的是TCP协议,网络通信使用的是Socket通信,具体程如下:
private void start()
{
try
{
CheckForIllegalCrossThreadCalls = false;
if (ipstring != null)
{
endpoint = new IPEndPoint(IPAddress.Parse(ip), 80);
listener = new TcpListener(endpoint);
listener.Start();
{
thread = new Thread(new ThreadStart(this.startsocketlisten));
thread.Start();
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
}
}
private void startsocketlisten()
{
bool acceptenum = true;
while (acceptenum==true)
{
try
{
if (listener.Pending())
{
Socket socket = listener.AcceptSocket();
Thread thread1 = new Thread(new ThreadStart(xianshi));
thread1.Start();
}
}
catch { }
}
}
public void xianshi()
{//数据解析}
作者: ff19191919 发布时间: 2008-03-13
作者: rangeon 发布时间: 2008-03-13
作者: dweng 发布时间: 2008-03-13
不懂,胡说
作者: lanwilliam 发布时间: 2008-03-13
bool acceptenum = true; 是个局部变量 啥时停止?不过看你thread应该是个类成员变量。
Socket socket = listener.AcceptSocket();
Thread thread1 = new Thread(new ThreadStart(xianshi));
thread1.Start();
你这个xianshi函数 怎么跟新建立起来的socket连接关联上的?
作者: beyondtkl 发布时间: 2008-03-13
listener.AcceptSocket()
这里你是不是写了在UI线程上面?
作者: Love_My 发布时间: 2008-03-13
listener.AcceptSocket()
这句是不是写了在UI线程上面
作者: Love_My 发布时间: 2008-03-13
listener.AcceptSocket()
这句是不是写了在UI线程上面
作者: Love_My 发布时间: 2008-03-13
{
bool acceptenum = true;
while (acceptenum==true)
{
try
{
if (listener.Pending())
{
Socket socket = listener.AcceptSocket();
Thread thread1 = new Thread(new ThreadStart(xianshi));
thread1.Start();
}
}
catch { }
}
}
bool acceptenum = true;
跟while语句,不死机才怪
作者: Fibona 发布时间: 2008-03-13
{
bool acceptenum = true;
while (acceptenum==true)
{
try
{
if (listener.Pending())
{
Socket socket = listener.AcceptSocket();
Thread thread1 = new Thread(new ThreadStart(xianshi));
thread1.Start();
}
}
catch { }
}
}
bool acceptenum = true;
跟while语句,不死机才怪
作者: Fibona 发布时间: 2008-03-13
{
bool acceptenum = true;
while (acceptenum==true)
{
try
{
if (listener.Pending())
{
Socket socket = listener.AcceptSocket();
Thread thread1 = new Thread(new ThreadStart(xianshi));
thread1.Start();
}
}
catch { }
}
}
bool acceptenum = true;
跟while语句,不死机才怪
作者: Fibona 发布时间: 2008-03-13
{
bool acceptenum = true;
while (acceptenum==true)
bool acceptenum = true;
跟while语句,不死机才怪
作者: Fibona 发布时间: 2008-03-13
{
bool acceptenum = true;
while (acceptenum==true)
bool acceptenum = true;
跟while语句,不死机才怪
作者: Fibona 发布时间: 2008-03-13
{
bool acceptenum = true;
while (acceptenum==true)
bool acceptenum = true;
跟while语句,不死机才怪
作者: Fibona 发布时间: 2008-03-13
listener.AcceptSocket()
这句是不是写了在UI线程上面
作者: Love_My 发布时间: 2008-03-13
作者: haierxiao 发布时间: 2008-03-13
该回复于2008-03-14 09:09:43被版主删除
- 对我有用[0]
- 丢个板砖[0]
- 引用
- 举报
- 管理
- TOP
|
#17楼 得分:0回复于:2008-03-13 21:06:21
|
作者: kafeiputao 发布时间: 2008-03-13
以前做过P2P聊天软件,你死机,就是没有用多线程,在VS 2005下调试多线程,我
的解决办法是Console.WriteLine()输出
作者: kafeiputao 发布时间: 2008-03-13
如果每次socket调用时间都不长,是短连接,可以用同步socket+多线程或socket+队列+多线程,但如果是长连接,建议用异步socket,这样效率比较高!
作者: pengjihong960 发布时间: 2008-03-13
作者: liubingonline 发布时间: 2008-03-13
{//数据解析}
问题是你的数据解析代码没有写好!需要用lock(object){}来处理或者用monitor方法来实现数据排队解析
作者: kafeiputao 发布时间: 2008-03-13
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28