Click to See Complete Forum and Search --> : OpenRemoteBaseKey doesnt release socket


nomad314
November 13th, 2009, 02:05 PM
I have made a test app (form) that opens a remote registry key using OpenRemoteBaseKey. I store the returned RegistryKey in a variable called key. I then call key.close().

If I run "net session" or "netstat" on the remote computer it shows an open connection in the ESTABLISHED state. This session does not close until briefly after I close my application. This is an issue because if more than 10 users are running my program to scan the same set of remote computers the remote computers hit their max connection limit.

Does anyone have a solution on closing this socket after the key is closed without ending the program?

Here is the sample code:


private void button1_Click(object sender, EventArgs e)
{
string ComputerName = "procl24";
RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,
ComputerName).OpenSubKey("SOFTWARE\\RemoteConnections");
key.Close();
}

I'm using VS2008 with .NET 3.5 SP1