Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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-Feb-12 19:35pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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[^].
DeepsMann at 7-Feb-12 6:05am
SAKryukov at 7-Feb-12 12:31pm
You are welcome.

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294

Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 2 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100