Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted

1 solution

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
 
Share this answer
 
v2
Comments
DeepsMann 7-Feb-12 6:05am    
Thanks..
Sergey Alexandrovich Kryukov 7-Feb-12 12:31pm    
You are welcome.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900