Thread: release resource for WebClient class

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    release resource for WebClient class

    Hello everyone,


    I find there is no resource release method for WebClient class, e.g. a method called "Close".

    My usage scenario is,

    1. Creating a new instance of WebClient;
    2. Post byte[] data using UploadData method, and retrieve return data also using byte[].

    In my scenario, are there any need to call some methods to release the resource (I suepect there is request stream handle and response stream handle to release)?


    thanks in advance,
    George

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    In the long run, the GC will take care of it. But WebClient is IDisposable, so why not use the "using" pattern:

    Code:
    using( WebClient wc = new WebClient() )
    {
    // do stuff with wc
    }
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 05:11 PM
  3. linker error
    By tasha302 in forum C++ Programming
    Replies: 3
    Last Post: 12-14-2006, 12:00 AM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM