Skip to content

Clean up resource in HttpListenerContext

George George

Asked Jun 4, 2008, 12:21 AM EDT2 answers
Share
LinkedInX

Hello everyone,


I currently clean-up resource in an HttpListenerContext instance in this way.

- Get Request.InputStream, and Close it;
- Get Response.OutputStream, and Close it.

My question is,

Is it the correct way to clean-up resouces? Since I did not fonud a Dispose or Close method for this class. Are there any more elegant way to clean-up resouce for HttpListenerContext?


thanks in advance,
George

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
            Request.InputStream.Close();
            Response.OutputStream.Close();

    Close the current stream and release the any resorces which is associated with them.

    Response.Clear();
    Clear all the content from current context.
    0
  • 0

    Thanks Paresh!

     

    I think if I completed input reading and ouput writing, I should call Request.InputStream.Close() and Response.OutputStream.Close(), other than call Clear, right?

     

    regards,

    George

    0