logo       

Re: It is safe to use Abort in HttpWebRequest?: msg#00121

windows.devel.dotnet.web

Subject: Re: It is safe to use Abort in HttpWebRequest?

You can call the Abort method on HttpWebRequest. This is completely different
from aborting a thread - they are two different operations. (They just happen
to use the same method name. For those of you who follow the whole misnamed
'latent typing' discussion, this is precisely the kind of reason I dislike the
idea of relying on names alone to identify semantics...)

I thought you were talking about Thread.Abort, since your original question was:

> I know that is not a good practice to use Abort to kill a
> thread. But What about in HttpwebRequest? It is safe?

The way I read this was "Is it OK to use Thread.Abort in conjunction with
HttpWebRequest?" But now I've seen your code, I realise this is not what you
meant.

Let me clarify my answer:

It's not OK to use Abort to kill a thread as a way of stopping an
HttpWebRequest.

It IS OK to use the HttpWebRequest.Abort method - this is not the same thing at
all as using Abort to kill a thread.

I hadn't realised you were talking about HttpWebRequest.Abort here, because you
started off by asking about aborting threads, something which is wholly
unrelated to HttpWebRequest.Abort. Sorry about that. Your code looks OK to me.


--
Ian Griffiths - DevelopMentor
http://www.interact-sw.co.uk/iangblog/

> -----Original Message-----
> From: Javier Martinez Álvarez
>
> Thanks Ian, can you give me any clue over how to stop the HttpWebRequest?
>
> I need to stop the HttpRequest because the timeout has expired, and I need
> to implement the timeout because in the asynchronous HttpRequest there
> isn't
> a implementation timeout.
>
> Now, my wrong implementation because use Abort is:
>
> //To set the timeout
>
> ThreadPool.RegisterWaitForSingleObject (result.AsyncWaitHandle, new
> WaitOrTimerCallback(TimeoutCallback), _httpWebRequest, _timeout, true);
>
>
> //To kill the request
> private void TimeoutCallback(object state, bool timedOut)
> { if (timedOut)
> {
> HttpWebRequest request = state as HttpWebRequest;
> if (request != null)
> {
> request.Abort();
> CleanUp();
> }
> }
> }

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise