错误-应用程序生成了无法处理的异常 [英] Error - Application has generated an exception that could not be handled

查看:235
本文介绍了错误-应用程序生成了无法处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在处理服务器应用程序.我已经创建了Windows应用程序并创建了TCPListener
保持聆听模式.当客户端发出请求时,它将为该客户端创建一个单独的线程.
来自不同客户端的所有请求都相同.

现在,我经常在离开办公室时保持运行状态.
今天我看到了这个异常消息

应用程序生成了无法处理的异常.

进程ID = 0xf50(3920),线程ID = 0xefc(3836)

是什么导致此异常发生??

请回复.

在此先感谢您.

Hello,

I am working on a server application. I have created a Windows Application and made a TCPListener
which keeps on listening mode. As a request comes from client it creates a separate thread for that client.
It is same for all requests from different client.

Now, I used to keep it running as I leave my office.
Today i saw this exception message

Application has generated an exception that could not be handled.

Process Id = 0xf50 (3920), Thread Id = 0xefc (3836)

What causes this exception to occur.?

Please reply.

Thanks in advance.

推荐答案

您犯了一个大错误:每个客户端有一个线程.线程是昂贵的资源,并且客户端的数量是不可预测的.您不应在运行时中间创建线程.最好从一开始就创建固定数量的线程,然后重新使用它们.对于TCP服务,您只能添加两个网络线程,但不能少于一个:一个用于接受新连接,另一个用于所有当前客户端.

有关更多详细信息,请阅读我过去的解决方案,其中介绍了这种设计的基本说明:
You are making a big mistake: a thread per client. Threads are expensive resources, and the number of clients is not predictable. You should not create threads in the middle of run-time. It''s much better to create fixed number of threads in a very beginning and re-use them. For a TCP service, you can add just two network threads, but no less: one for accepting new connections, one more the work with all current clients.

For further detail, please read my past solution where I present a skeleton description of such design: Multple clients from same port Number[^].

—SA


这篇关于错误-应用程序生成了无法处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆