.NET Framework Bookmark and Share   
 index > .NET Framework Networking and Communication > Pending TCP connection after WMI query
 

Pending TCP connection after WMI query

Hi, all

We have an application with WMI query in a loop. We find occasionally memory leak on Vista 32 no_SP/SP1/SP2. When there is memory leak, there are hundreds of TCP connections in “Established�state with WMI port as target. (by netstat -an)

The code is like below

Class A

{

public ManagementScope scConnect;

public static DoWork

{

While(true)

{

scConnect = new ManagementScope(�;

scConnect.Connect();

�/span>

Thread.Sleep(5000);

}

}

}

This issue can only be re-produced on 1-2 of 10 test machines after 10 hours, but quite stably.


When we wrote a sample console application with precisely the same WMI behavior, the memory leak issue can not be re-producible and there is no pending TCP connection.


We tried to disconnect by set ManagementScope (scConnect) to be null as below code, however, we still find one leak among 10 after 1 night.

scConnect = null;

Any hint? Thanks in advance.

Jack

Jack-Yang
You might want to ask a different forum. I dont think you will find an answer here.

feroze
--
My blog
Feroze Daud
As Feroze notes there may well be a better forum.

Its surprising there's no Disconnect method nor Dispose/IDisposable. Can't you reuse the object? Don't create a new instance each time round the loop; initialise it the first time, and only if an error occurs recreate it...
http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
Alan J. McFarlane
As Feroze notes there may well be a better forum.

Its surprising there's no Disconnect method nor Dispose/IDisposable. Can't you reuse the object? Don't create a new instance each time round the loop; initialise it the first time, and only if an error occurs recreate it...
http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered

............

I had simplied my application to be a simple GUI with percisely the same backend operation (include ICMP scan, WCF query and WMI query). There is no such issue after running for several days on several dozen of test machines.

So, it seems to be not caused by object creation in loop. It seems UI contributes the issue and causes a un-clean release of TCP connection after WMI query, so wired.

I am isolating this issue by disabling modules of UI one by one and trying re-produce. The re-produce is so difficult and the task is so painful.

Any hint for efficient isolation?

Jack
Jack-Yang
OK so that sounds like a message loop and/or COM apartment type problem. Is there anything about those subjects in the ManagementScopedocumentation? The first thing I'd try would be to change your code to ensure that you only create ManagementScope object on the UI thread (so Invoke/etc onto the UI thread).
http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
Alan J. McFarlane

Looks as if I guessed backward. Seems WMI wants an MTA thread http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/3cddb1b9-a99b-4843-bbb1-c95f7f5f958c http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic49733.aspx Thus you should do that not on the UI thread...


http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
Alan J. McFarlane

You can use google to search for other answers

Custom Search

More Threads

• a connection problem
• Failure sending mail with ASP.NET 2.0
• Build Your Own Memory Optimizer With C#
• Clickonce and WCF Services
• client not returning server cookie
• ftp sockets in c#
• Network Programming
• Control doesn't seem to read value from viewstate
• IIS7 with FTP/SQLSERVER AND FILES/SPACE QUOTA
• How to notify user in voice before send a Fax