473,395 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Socket.BeginConnect cleanup

Hi

I am using the BeginConnect function on my socket but I am not exactly sure
how I am supposed to clean up after this call.
After the connecion attempt has completed I call EndConnect passing in the
IAsyncResult I received from the BeginConnect and then I close the socket.
However when I look in Task Manager the handle count for my program goes up
everytime I run this function. I tried closing the AsyncWaitHandle of the
IAsyncResult too but that didn't seem to help either.

Thanks in Advance
Peter Chapman
Nov 16 '05 #1
2 6931
Peter,

Can you show sample code showing how you are closing these things? It
would seem that you are closing all the right things, but without seeing the
code, it is hard to tell.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Peter Chapman" <Pe**********@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.com...
Hi

I am using the BeginConnect function on my socket but I am not exactly
sure
how I am supposed to clean up after this call.
After the connecion attempt has completed I call EndConnect passing in the
IAsyncResult I received from the BeginConnect and then I close the socket.
However when I look in Task Manager the handle count for my program goes
up
everytime I run this function. I tried closing the AsyncWaitHandle of the
IAsyncResult too but that didn't seem to help either.

Thanks in Advance
Peter Chapman

Nov 16 '05 #2
Hi

I use this code to connect:

//Connect asynchronously
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
pendingConnect = socket.BeginConnect(connectThreadMessage.RemoteEnd Point,
new AsyncCallback(AsyncOperationCompleteCallback), socket);
then in the callback I pass the message back to my thread and use this code:

socket.EndConnect(pendingConnect);
socket.Close();
socket = null;

Everytime I execute this task manager shows the handle count for my process
increasing by 1. If I force a garbage collection then all the handles get
released.

Peter

"Nicholas Paldino [.NET/C# MVP]" wrote:
Peter,

Can you show sample code showing how you are closing these things? It
would seem that you are closing all the right things, but without seeing the
code, it is hard to tell.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Peter Chapman" <Pe**********@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.com...
Hi

I am using the BeginConnect function on my socket but I am not exactly
sure
how I am supposed to clean up after this call.
After the connecion attempt has completed I call EndConnect passing in the
IAsyncResult I received from the BeginConnect and then I close the socket.
However when I look in Task Manager the handle count for my program goes
up
everytime I run this function. I tried closing the AsyncWaitHandle of the
IAsyncResult too but that didn't seem to help either.

Thanks in Advance
Peter Chapman


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: faktujaa | last post by:
Hi, I am having some problem with callback used in socket implementation. private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref Socket rsocClient) { try { // Create remote end...
2
by: Bryan Mayland | last post by:
I've got a problem with a System.Net.Socket that is failing on connect. Each time I attempt a connection, 3 handles are allocated, and when the connect fails 2 handles are freed. If left retrying...
3
by: cocla | last post by:
I try to connect to server using following codes: (smart device application) Socket s=new Socket(); try { s.connect(host);//host is an object of IPEndPoint class } catch (SocketException) {
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
2
by: rs | last post by:
I am writing a client/server program. currently the server and the client are running in the same computer. the client used to connect fine to the server with the following code: Dim ipHostInfo...
3
by: Mike Schilling | last post by:
How does one put a timeout on an attempt to connect a socket? There's no timeout parameter to Socket.Connect(), and while there are socket options for send and receive timeouts, there is none for...
4
by: carl_bevil | last post by:
I would like to use a single port to connect to a server. I would like to be able to disconnect a socket using this port and then be able to connect again (on the same port) immediately. I know...
2
by: semedao | last post by:
Hi , someone know the reason and how to handle it? thanks
8
by: panko | last post by:
Hello, I can't manage with asynchronous socket communication. :( I wrote a class CSocket.cs. This class is taking care of sending strings to LED display. This display is actually communicating...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.