A few questions as to how beginread on a tcpclient or socket. If I start beginread, I believe the thread comes from the thread pool. Does the thread start when beginread is called, when data starts arriving, or when the specified number of bytes are recd and the ascyn callback method is started? The reason I ask, is I am wondering if I have a large number of connections reading and the clients that are sending data are slow (or not at all), will the thread pool quicklty fill up with threads that aren't doing anything waiting on data to be recd from clients?
The other related question I have is related to how to cleanly shutdown if there are async reads going on. Can you just close the tcpclient down from the main thread and the async readers go away gracefully, or do you have to do some sort of explicit locking on something like the tcpclient itself?
Loading
Don KookerPosted Apr 6, 2008, 7:27 PM
Sorry, I think my 2nd question was poorly written. My concern is not how to clean up the connection, but how to cleanly shutdown my application. If the user tries to close down the application, and a beginread has already been issued, then that beginread could be either still waiting on the network to deliver the number of bytes indicated in the beginread (eg. what if the client on the other end of the connection is slow or not responding) or may be in the middle of running the ascyc callback function if all teh data has been recd.
Can my main thread close the tcp connection, which would presumably cause the thread which is running in the background processing that read to stop reading or waiting to read. My concern being that both the ascyn begin read and the main program would be manipulating the same tcpclient object at the same time?
Bechir BejaouiPosted Apr 6, 2008, 12:32 PM
synchrone:
TcpClient within the TCP (Transmission Control Protocol) synchrone context
asynchrone:
UdpClient within the UDP (User Diagram Protocol) asynchrone context
For the second question, to save the headakes, you can create a class warpper for your unmanaged code and overload the dispose method of this class wrapper so that if the task is achived then the ressources are collected
or you can invoke the garbage collector to do the mission