473,748 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread.Abort not really aborting thread.

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.
Jun 12 '07 #1
4 15886
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]
- mv*@spam.guard. caspershouse.co m

"Mufasa" <jb@nowhere.com wrote in message
news:e2******** ******@TK2MSFTN GP05.phx.gbl...
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.
Jun 12 '07 #2
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 [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:7E******** *************** ***********@mic rosoft.com...
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]
- mv*@spam.guard. caspershouse.co m

"Mufasa" <jb@nowhere.com wrote in message
news:e2******** ******@TK2MSFTN GP05.phx.gbl...
>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.

Jun 12 '07 #3
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]
- mv*@spam.guard. caspershouse.co m

"Mufasa" <jb@nowhere.com wrote in message
news:%2******** *********@TK2MS FTNGP02.phx.gbl ...
>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 [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote
in message news:7E******** *************** ***********@mic rosoft.com...
> 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]
- mv*@spam.guard. caspershouse.co m

"Mufasa" <jb@nowhere.com wrote in message
news:e2******* *******@TK2MSFT NGP05.phx.gbl.. .
>>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.


Jun 12 '07 #4

"Mufasa" <jb@nowhere.com wrote in message
news:e2******** ******@TK2MSFTN GP05.phx.gbl...
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()

Jun 12 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2388
by: cottonviking | last post by:
Greetings, all! I've been pondering the pitfalls of aborting a secondary thread in a service app I'm writing (VB, fx v1.1). Everything I've read so far pretty much dissuades one from aborting one thread from another, and I'm almost at the point of acquiescing but curiosity leads me on. Below is a procedure template that I wonder might guarantee behavior during an abort, and I'd like to get some feedback in case it's just plain nonsense.
4
7391
by: Stephan Steiner | last post by:
Hi I'm having some weird threading issues.. almost at random, if I dare change a line of my code, the shutdown sequence gets messed up. I'm using a thread to receive data from the network, that I suspend and resume whenver needed. In order to properly shut down the program every thread has to be aborted. So, I override OnClosing(CancelEventArgs e) in my main GUI program, and have it perform the following on the thread: if...
16
10093
by: Bill | last post by:
Say I have a childThread currently is running a finally block to cleanup external resources. At the same time the main thread calls childThread.Abort(). The question is: when the ThreadAbortException is thrown, does the childThread finish the remaining code in the finally block?
7
3292
by: Morris | last post by:
I want to abort a running thread, so I call MyThread.abort() function. My problem is this thread runs "almost" like a while(true) loop and I don't want the Abort() function interrupts the thread at any point in the thread. In fact, I have a section of code needs to be "protected" from being interrupted. How can I make sure Abort() will not land anywhere winthin this block? In other words, the Abort() must wait until this block of code is done...
2
2046
by: Xarky | last post by:
Hi, I am writing a small program, that makes use of threads. Now in on of the threads I have a critical section, where I am using the Monitor to handle this. *** Thread_1 *** started for(...) { ....doing some work Monitor.Enter(Thread_1);
5
3139
by: [Yosi] | last post by:
Why I can't abot a susspended thread. Who can terminat a thread imediatly without consider to its stat or execution?
1
4474
by: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am assuming that this is not an uncommon piece of software. I want to get an architecture that conforms as closely as possible with the recommendations from Microsoft on developing Windows Services, but to be honest I have found difficultly in...
6
2943
by: mehdi | last post by:
Hi folks, You know, the Thread class has got a method named Abort which according to the msdn: "Raises a ThreadAbortException in the thread on which it is invoked, to begin the process of terminating the thread. Calling this method usually terminates the thread." I've had a long discussion with someone on not to use the mentioned method unless under the most extreme cases. I believe that it's
20
5095
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
John Dohn wrote: When I do this, I put a special value in the queue (like None) and in the worker thread, check for the special value and exit if found. Threads can also be marked as "daemon threads" (see docs for threading.Thread objects). This will make the application terminate if only "daemon threads" are left. So best would probably be soemthing like
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.