Solved

closing threads

Posted on 2003-11-24
6
1,020 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

777 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