Solved

closing threads

Posted on 2003-11-24
6
1,019 Views
Last Modified: 2011-09-20
How do I end a thread?

I used the sample code below to execute the thread:

procedure Form1.Button1CLick();
var vThread : Integer;
begin
      vThread := Thread.create(False);
end;

When I click Button2, the Thread should stop... How can I do that?
I thought of using ExitThread but I dont know how to use the GetExitCodeThread function to get the exit code of the thread.

PLease help... thanks
0
Comment
Question by:LORD_CHO
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
snehanshu earned 25 total points
ID: 9816084
To stop a thread,
  1) Buy ExEx premium services
  2) Search in Delphi TA for Thread stop
  3) Click on this link from the search results
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20390347.html

;-)
NOTE: 1 and 2 are now not required, may be for your next Q!

HTH,
...Snehanshu
0
 

Author Comment

by:LORD_CHO
ID: 9816774
hi ...Snehanshu
  thanks fo replying...

I did the example you have in your 3rd comment, but I always get "Access Violation" after executing the program. You see, my Thread (.execute) is located in Unit2...... But I am stopping it from unit1...
I have included the Unit2 in the uses of  Unit1... but still I receive the access violation.
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9817483
LORD_CHO,

  I do not know too much about threads, but can you provide code related to your thread in both units (of how you are creating and terminating )?
  I'll try, but if not me, others might be able to help.

...Shu
0
 
LVL 5

Assisted Solution

by:Hypoviax
Hypoviax earned 25 total points
ID: 9822557
Shehansu Hi seen you around alot lately,

Any way LORD_CHO how about you try wrapping a try except block around the code in Shehansu's code. This may help prevent the violation from occuring. Use the red dot things to trace the place where the violation is occuring but first of all use the try except. You will still see the error in delphi unless you turn stop on delphi exceptions off:

goto Tools-Debugger Options- Language Exceptions - Turn off stop on delphi exceptions

Regards,

Hypoviax
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now