473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Thread.Abort() not triggering

Hello,

I have searched far and wide, and i found millions of post telling "BAD" or "you should have regular checks" but that wont work for me.

the problem is, i have a program that is all about queries. the thread.abort function does not trigger in the middle of a query. now this is a lengthy query on a slow server, and just using timeout wont work because then i will almost never get the query. (3 out of 20 i estimate)
but the impatient users might want to bash a cancel button and retry.

what i want is the thread killed. but still usable. again, thread abort is not the way for me because i want to kill it mid-query.

any way to do this?
Mar 3 '09 #1
14 1726
Plater
7,872 Expert 4TB
Thread.Abort() just raisies the ThreadAborting exception on the thread, which means the Thread has to be transitioning to process the message. If its busy with an IO call, it won't get the message until its done.
Mar 3 '09 #2
ah, well is there any way to just kill it off instantly? because sometimes the query can take up to 10 minutes to process. its a reasonably large database and im running a count query against it.
Mar 3 '09 #3
Plater
7,872 Expert 4TB
I think there is a way to do the queries in async mode, and you cancel that way?
Mar 3 '09 #4
async mode? (im sorry i just started with threading)
and how would i cancel that isnt that just another thread?
Mar 4 '09 #5
vekipeki
229 Expert 100+
Instead of killing this thread, you can just signal it to end, and create a new thread (e.g. from a thread pool). You might also want to limit the number of threads per single session.

So, "you should have regular checks" would mean you should raise some "end" flag (or AutoResetEvent or something) without explicitly aborting your previous thread, and make the thread ends itself when it gets the signal.
Mar 4 '09 #6
hmmm, but then the problem is that the start button triggers thread A
when thread A wants to abort and keeps in the query then it wont do much good if it spawns another thread. unless i can make that dynamic.
Mar 4 '09 #7
vekipeki
229 Expert 100+
the query can take up to 10 minutes to process
10 minutes is a long time to wait for a customer, do you think you can somehow avoid a count query?

Also, making a column "NON NULL" might improve performance for COUNT(col_name), because apparently there should be less checks to do in that case (table metadata should already contain the count). Caching the indexes in memory (that should be a server tweak) should also improve performance. Or see if you can get rid of Count if possible.

If thread A is busy waiting for results, and you cannot abort it, then there is no reason to create another thread which will wait for the first thread to finish. Try to identify the exact point at which your thread A blocks, and then you will know what to do.
Mar 4 '09 #8
it usually hangs up at the queries, i have found out that i can cancel the query so i can try to interrupt it like that.
the count is essential since it sets the progressbar maximum value, this will show the user how far the (lengthy) progress is coming along.
i will try column [0] because collumn names could differ
Mar 4 '09 #9
vekipeki
229 Expert 100+
the count is essential since it sets the progressbar maximum value
That is actually what I meant: I would give greater priority to speed than progressbar accuracy (I wouldn't call progressbar essential).

So, if you can get (for example) maximum ID number in your table (which should be much faster than Count), then you can display the progress bar which will update as you move along (even if you don't have some IDs in your table). And progress bar doesn't update while you are getting Count, anyway.

(I understood that Count is the slow query that's giving you the problems, but if other queries are slow also, then it's a different story)
Mar 4 '09 #10
The id numbers arent generated by the database itself, it is all a list of 4 to 8 generated numbers.
i cant make any changes to the database or the server though.
Mar 4 '09 #11
Plater
7,872 Expert 4TB
I have to agree with vekipeki here.
If given the choice between accurate statusbar, and having a task take 10minutes less, I would take the 10minutes less.
Most progressbars are just a "guess" anyway.
When I use them, I move them by task, not weight of task.
Like if I have 10 things that need to be done, completeing a task moves the bar 1/10 of the way. Regardless of if one task is very simple and another is very complex.
Mar 4 '09 #12
then it will be no statusbar at all, its just a reader that merges databases... since the amount of records may change a fixed number isnt going to help that much either...
Mar 4 '09 #13
Plater
7,872 Expert 4TB
Sounds good. I would recomend a splash screen of sorts that says like "Merging Databases" and if you have it available, everytime a task finishes(or starts) just throw that up on the splash.

"Merging Datasbase: (tablename)"
.
.
.
"Merging Datasbase: (Some ofther tablename)"
Mar 4 '09 #14
i do have something like
"reading row"
"getting parent for <ID>"
and i like having the overview of "completeness" since it can give a little bit of insight on how long it might take.

however i have been told the server used is poo though, so it might as well be that. some other times the query gets through in < 20 seconds...
Mar 4 '09 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Daisy | last post by:
From this page: http://www.c-sharpcorner.com/2/mt_beginner1.asp Thread class's Abort method is called to kill a thread permanently. Make sure you call IsAlive before Abort. if (...
7
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...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
18
by: Urs Vogel | last post by:
Hi I wrote an application server (a remoting sinlgeton), where processes must be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and only after a Thread.Abort(), this...
1
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...
6
by: Joe HM | last post by:
Hello - I have a function that calls Thread.Abort() to stop a thread in a _Closed() Method of a GUI. The thread contains a blocking call on a TCP socket and that is the easiest way to stop...
23
by: Boltar | last post by:
Hi I'm writing a threading class using posix threads on unix with each thread being run by an object instance. One thing I'm not sure about is , if I do the following: myclass::~myclass() {...
5
by: andrew | last post by:
Hi, I have the following issue with the Thread.Abort(): The main thread creates a worker thread which waits on a process termination. void ThreadProc() { Process proc =...
6
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...

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.