Thread.Abort not really aborting thread.

M

Mufasa

Is there any way to force a thread to abort and really have it abort? I have
a thread that every once in a while gets hung to so I kill it. Problem is I
have a thread that every once in a while gets stuck (I'm working on why that
happens) and I want to kill it. I do a thread.abort and the status becomes
abortrequested but never actually goes through.

If it were an actual process I could kill it but there seems to be no real
kill for thread other than abort.

Any thoughts?

TIA - Jeff.
 
N

Nicholas Paldino [.NET/C# MVP]

Are you performing any interop on the thread? If the call stack is
waiting on an interop call, then the thread can not abort until the
unmanaged code completes.

I would concentrate more on finding out why the thread hangs, as
aborting is not really the optimal way to signal that a thread should finish
its work.
 
M

Mufasa

I have a service that goes out and crawls the web. Apparently some pages are
prompting for user input, which obviously you can't do with a service, so
that the thread stops.

I'm using HttpWebResponse with a timeout of 30 seconds and keepalive =
false.

I already am checking for the timeout and that seems to work when the page
just doesn't load. But there are some pages that it seems to get stuck on
and I don't know why.

My thought is that if it takes to long to get the pages, I'll just abort it.

Any thoughts?

TIA - Jeff.

Nicholas Paldino said:
Are you performing any interop on the thread? If the call stack is
waiting on an interop call, then the thread can not abort until the
unmanaged code completes.

I would concentrate more on finding out why the thread hangs, as
aborting is not really the optimal way to signal that a thread should
finish its work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mufasa said:
Is there any way to force a thread to abort and really have it abort? I
have a thread that every once in a while gets hung to so I kill it.
Problem is I have a thread that every once in a while gets stuck (I'm
working on why that happens) and I want to kill it. I do a thread.abort
and the status becomes abortrequested but never actually goes through.

If it were an actual process I could kill it but there seems to be no
real kill for thread other than abort.

Any thoughts?

TIA - Jeff.
 
N

Nicholas Paldino [.NET/C# MVP]

Jeff,

I doubt that the page is prompting for user input. When a page prompts
for user input, then that means that a JavaScript call, or embedded object
is asking for input. However, that requires the page to actually be
interpreted, which the HttpWebRequest/HttpWebResponse classes just don't do.

The timeout should work. Can you post an example of a timeout that
doesn't work?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mufasa said:
I have a service that goes out and crawls the web. Apparently some pages
are prompting for user input, which obviously you can't do with a service,
so that the thread stops.

I'm using HttpWebResponse with a timeout of 30 seconds and keepalive =
false.

I already am checking for the timeout and that seems to work when the page
just doesn't load. But there are some pages that it seems to get stuck on
and I don't know why.

My thought is that if it takes to long to get the pages, I'll just abort
it.

Any thoughts?

TIA - Jeff.

Nicholas Paldino said:
Are you performing any interop on the thread? If the call stack is
waiting on an interop call, then the thread can not abort until the
unmanaged code completes.

I would concentrate more on finding out why the thread hangs, as
aborting is not really the optimal way to signal that a thread should
finish its work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mufasa said:
Is there any way to force a thread to abort and really have it abort? I
have a thread that every once in a while gets hung to so I kill it.
Problem is I have a thread that every once in a while gets stuck (I'm
working on why that happens) and I want to kill it. I do a thread.abort
and the status becomes abortrequested but never actually goes through.

If it were an actual process I could kill it but there seems to be no
real kill for thread other than abort.

Any thoughts?

TIA - Jeff.
 
M

Mr. Arnold

Mufasa said:
Is there any way to force a thread to abort and really have it abort? I
have a thread that every once in a while gets hung to so I kill it.
Problem is I have a thread that every once in a while gets stuck (I'm
working on why that happens) and I want to kill it. I do a thread.abort
and the status becomes abortrequested but never actually goes through.

If it were an actual process I could kill it but there seems to be no real
kill for thread other than abort.

Any thoughts?

Thread.Abort()

then follow it with

Thread.Join()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top