http://blog.downtownsoftwarehouse.com/2006/11/14/using-the-ping-class-in-net-20-without-memory-leaks/
A longer diatribe that reaches the same conclusion:
http://www.julmar.com/blog/mark/PermaLink,guid,fc83197b-ce2d-47ab-b70a-db352085b370.aspx
And just in case the links above die, here's the gist of it:
"...you must explicitly call IDisposable.Dispose(), or you’ll end up with the inherited Dispose() method which doesn’t do anything useful at all in this case. You can do this by casting the Ping object to IDisposable."
private void Refresh(Object sender, EventArgs args)
{
Ping ping = null;
try
{
ping = new Ping();
ping.PingCompleted += PingComplete;
ping.SendAsync(defaultHost, null);
}
catch
{
((IDisposable)ping).Dispose();
}
}
private void PingComplete(Object sender, PingCompletedEventArgs args)
{
((IDisposable)sender).Dispose();
}
1 comment:
top [url=http://www.c-online-casino.co.uk/]uk bonus casino[/url] coincide the latest [url=http://www.realcazinoz.com/]casino[/url] autonomous no consign bonus at the foremost [url=http://www.baywatchcasino.com/]casino online
[/url].
Post a Comment