tthread

delphi - terminate all the threads (TThread) on closing application

霸气de小男生 提交于 2020-01-10 09:22:51
问题 My application is a tcp/ip server, with main thread created only once & listening all the time. When new client connects, the main thread creates the new thread of TClientThread type. There is however no list of running Client threads, as that would make my app a bit complicated... is there any way to execute "terminate" method on all the threads, even if the thread is busy (in my case "busy" means it's waiting for the data, where the timeout set is about 30 sec ... so I have to kill it

delphi - terminate all the threads (TThread) on closing application

◇◆丶佛笑我妖孽 提交于 2020-01-10 09:21:21
问题 My application is a tcp/ip server, with main thread created only once & listening all the time. When new client connects, the main thread creates the new thread of TClientThread type. There is however no list of running Client threads, as that would make my app a bit complicated... is there any way to execute "terminate" method on all the threads, even if the thread is busy (in my case "busy" means it's waiting for the data, where the timeout set is about 30 sec ... so I have to kill it

Delphi: TThreadList sometimes lock program

情到浓时终转凉″ 提交于 2020-01-07 09:52:11
问题 Sometimes this function locks my program, and it's freezes until i close it. What is wrong here ? function del_from_list(id:string):boolean; var i : integer; begin Result := True; try with global_list.LockList do begin for i:=0 to Count-1 do begin if Tthread_list(Items[i]).id = id then begin Delete(i); break; end; end; end; finally global_list.UnlockList; end; end; the class Tthread_list = class public id : string; constructor Create(const id: string); end; I'm adding to the list like that:

Delphi: TThreadList sometimes lock program

纵然是瞬间 提交于 2020-01-07 09:52:05
问题 Sometimes this function locks my program, and it's freezes until i close it. What is wrong here ? function del_from_list(id:string):boolean; var i : integer; begin Result := True; try with global_list.LockList do begin for i:=0 to Count-1 do begin if Tthread_list(Items[i]).id = id then begin Delete(i); break; end; end; end; finally global_list.UnlockList; end; end; the class Tthread_list = class public id : string; constructor Create(const id: string); end; I'm adding to the list like that:

Free a TThread either automatically or manually

柔情痞子 提交于 2019-12-31 22:27:10
问题 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 FreeOnTerminate, and I've read that you have to be careful using it. My question is, is the following code correct? procedure TMyThread.Execute; begin ... Do some processing Synchronize(ThreadFinished); if Terminated then exit; FreeOnTerminate := true; end;

how to let the TThread to keep working in background and showing me the result in a Listbox?

烈酒焚心 提交于 2019-12-23 02:43:50
问题 I have to develop a program to keep watching values in databases based on a Select statement given by me the watched values can be changed at anytime and my program must sense the changes based on a result of the select statement which is given by me i want to watch the select result by using TThread because my system is also has another features and the user need to work on it not only to watch values. how to do it using TThread in Delphi XE2 am using VCL...no .Net Regards. 回答1: [Edit]

A proper way of destroying a TThread object

五迷三道 提交于 2019-12-18 12:55:28
问题 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, the objects destroyed inside the class's destructor are no longer accessed. Therefore it is necessary to call Terminate to set the Terminated flag that the thread has to check to know whether to exit or not, and then call the WaitFor() method.

Why does a MessageBox not block the Application on a synchronized thread?

£可爱£侵袭症+ 提交于 2019-12-18 02:57:35
问题 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 NOT block the main application, however sleep does just as expected. Why is that? type TTestThread = class(TThread) private procedure SynchThread; protected procedure Execute; override; public constructor Create(CreateSuspended: Boolean); end;

With what delphi Code should I replace my calls to deprecated TThread method Suspend?

强颜欢笑 提交于 2019-12-17 22:20:11
问题 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 TMyThread.Execute; begin while (not Terminated) do begin if PendingOffline then begin PendingOffline := false; // flag off. ReleaseResources; Self.Suspend; // suspend thread. { evil! ask Barry Kelly why.} // -- somewhere else, after a long time, a user

Delphi (XE2) Indy (10) Multithread Ping

南楼画角 提交于 2019-12-17 15:36:52
问题 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 fine now but takes ages when most computers are offline. So what I am trying to do is to write a MultiThread Ping but I am quite struggling with it. I have seen only very few examples over the internet and no one was matching my needs, that's why I