Click here to Skip to main content
13,343,856 members (75,145 online)
Rate this:
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 7-Feb-12 6:05am
SAKryukov 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 2 Feb 2012
Copyright © CodeProject, 1999-2018
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