Questions tagged [tthread]
92 questions
16
votes
4 answers
With what delphi Code should I replace my calls to deprecated TThread method Suspend?
It has been asked before, but without a full answer. This is to do with the so called famous "‘Fatal threading model!’".
I need to replace this call to TThread.Suspend with something safe, that returns when terminated or resumed:
procedure…

Warren P
- 65,725
- 40
- 181
- 316
16
votes
2 answers
A proper way of destroying a TThread object
This question may seem trivial, but I hope you won't ignore it.
Before destroying a TThread object it is usually necessary to wait until the thread that called the TThread.Execute() method finishes, for only then can we be sure that, for instance,…

Mariusz Schimke
- 3,185
- 8
- 45
- 63
15
votes
1 answer
What's wrong with using TThread.Resume?
Long ago, when I started working with threads in Delphi, I was making threads start themselves by calling TThread.Resume at the end of their constructor, and still do, like so:
constructor TMyThread.Create(const ASomeParam: String);
begin
…

Jerry Dodge
- 26,858
- 31
- 155
- 327
13
votes
5 answers
How to implement thread which periodically checks something using minimal resources?
I would like to have a thread running in background which will check connection to some server with given time interval. For example for every 5 seconds.
I don't know if there is a good "desing pattern" for this? If I remember corretly, I've read…

Wodzu
- 6,932
- 10
- 65
- 105
13
votes
4 answers
Delphi unit test for a TThread with FreeOnTerminate = True
What is the best way to write a Delphi DUnit test for a TThread descendant when FreeOnTerminate = True? The TThread descendant returns a reference which I need to test for, but I can't figure out how to wait for the thread to finish in the…

Rick Wheeler
- 1,142
- 10
- 22
11
votes
4 answers
Delphi TThread.CurrentThread and EAccessViolation - Is This a Bug or My Incompetence..?
In Delphi 2009 I'm finding that any time I use TThread.CurrentThread in an application, I'll get an error message like the following when the application closes:
Exception EAccessViolation in module ntdll.dll at 0003DBBA.
Access violation at address…

MB.
- 7,365
- 6
- 42
- 42
11
votes
4 answers
Delphi (XE2) Indy (10) Multithread Ping
I have a room with 60 computers/devices (40 computers and 20 oscilloscopes Windows CE based) and I would like to know which and every one is alive using ping. First I wrote a standard ping (see here Delphi Indy Ping Error 10040), which is working…

HpTerm
- 8,151
- 12
- 51
- 67
10
votes
1 answer
How to use LoadKeyboardLayout in a background thread?
I'm using the LoadKeyboardLayout function to load and activate the keyboard layout this way:
procedure TfrmMain.eSearchEnter(Sender: TObject);
begin
LoadKeyboardLayout('00000429', KLF_ACTIVATE);
end;
It works perfectly, but it freezes the active…

Farshad H.
- 303
- 4
- 16
9
votes
6 answers
Raising Exception in TThread Execute?
I just realized that my exceptions are not being shown to the user in my threads!
At first I used this in my thread for raising the exception, which does not work:
except on E:Exception do
begin
raise Exception.Create('Error: ' +…

Jeff
- 12,085
- 12
- 82
- 152
9
votes
5 answers
Free a TThread either automatically or manually
I have a main thread and a separate thread in my program. If the separate thread finishes before the main thread, it should free itself automatically. If the main thread finishes first, it should free the separate thread.
I know about…

Steve
- 2,510
- 4
- 34
- 53
9
votes
3 answers
Why does a MessageBox not block the Application on a synchronized thread?
As far as I understand and know the method of the TThread Class, if you synchronize your code, it actually get's executed in the main Application Thread (just like a timer/buttonclick/etc.)
I've been playing around and noticed that a MessageBox DOES…

Ben
- 3,380
- 2
- 44
- 98
8
votes
2 answers
Thread Error: The Handle is Invalid (6) when trying to Free a suspended thread
In a given example I am receiving an exception when calling AThread.Free.
program Project44;
{$APPTYPE CONSOLE}
uses
SysUtils, Classes, Windows;
type
TMyException = class(Exception);
var
AThread: TThread;
begin
AThread :=…

Wodzu
- 6,932
- 10
- 65
- 105
8
votes
1 answer
TThread and COM - "CoInitialize has not been called", although CoInitialize is called in the constructor
I'm trying to use COM interface within a thread. From what I have read I have to call CoInitialize/CoUninitialize in each thread.
While this is working fine:
procedure TThreadedJob.Execute;
begin
CoInitialize(nil);
// some COM stuff
…

forsajt
- 857
- 1
- 7
- 13
6
votes
6 answers
How do I port code for Borland C++ builder to Linux?
I have source code for a Windows DLL that is written in C++ and uses Visual Component Library. Now my task is to port that to Linux, but I don't have source code for the VCL itself, or any kind of documentation (and I have never worked with Borland…

ajanicij
- 415
- 3
- 12
6
votes
2 answers
"Pausing" A Thread With A Property
I have a TThread object and want to be able to start/stop the thread via a button on the main form of the program. I've been looking into ways to do this and so far I have the following ideas:
Terminate and Free the thread when the user clicks stop…

user1970794
- 253
- 3
- 16