The implementation of IDisposable Pattern of System. Net. NetworkInformation. Ping may be wrong

Source: Internet
Author: User

Ping class as expected holds an unmanaged resource viewed via reflector. in most cases, as I know, the class implements an explicit IDisposable. dispose method. and Ping does it the same way as others, like EventWaitHandle. but unlike EventWaitHandle, it also inherits Component, an implementation class, which implements an implicit Dispose from IDisposable. as an outsider, I am surprising to compose my code like this:
Ping p = new Ping ();
//...
P. Dispose ();
As the Component class follows standard IDisposable pattern. there is a protected virtual Dispose (bool) method inside it. an interesting observation is the Ping doesn't override that protected method and implment the explicit IDisposable. dispose as follow:
// From reflector (. net 2.0)
Void IDisposable. Dispose ()
{
InternalDispose ();
}

The InternalDispose () just closes everything and returns.

So if anyone acts like me, call Ping. Dispose () will get unexpected result.

I just got a reply from MSFT (Tratcher, a System. net developer in Windows Core Networking) that "Your observations are correct. this has been fixed in. net 4.0 Beta 2, which was released this week. take a look and let us know what you think."

At last, I just got my beta 2 installed today. It looks pretty good.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.