Autor Beitrag
sky21
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 141

W7
D2010, XE2
BeitragVerfasst: Mo 24.04.06 12:48 
Hi Hackers,
...Ich habe eine connect() Methode, welche blockieren könnte. Damit das Programm nun nicht stehen bleibt, will ich nun das Ganze in einen TThread auslagern. Falls die Timeout-Zeit abgelaufen ist und der Thread von selber noch nicht beendet worden ist, möchte ich diesen gerne 'abschiessen'. Wie geht das? gibt es 'killthread()' oder so etwas ähnliches?

PS: Es ist die connect() Methode von TIdFTP, welche ab und zu 'mal für Ärger sorgt.
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Di 25.04.06 07:49 
Hallo,

gibt es da nicht
ausblenden Delphi-Quelltext
1:
2:
3:
TThread.terminate := True;
vorher vielleicht
TThread.freeOnTerminate := True;

Gruss Horst
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 25.04.06 08:04 
Die Indies besitzen von Haus aus eine Anti-Freeze-Komponente. Diese solltest Du wenn möglich vorher probieren, da das die Hauseigene Lösung ist. Ansonsten sollte es für dich auch möglich sein, das Socket asynchron zu betreiben.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
sky21 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 141

W7
D2010, XE2
BeitragVerfasst: Di 25.04.06 09:07 
user profile iconHorst_H hat folgendes geschrieben:
Hallo,

gibt es da nicht
ausblenden Delphi-Quelltext
1:
2:
3:
TThread.terminate := True;
vorher vielleicht
TThread.freeOnTerminate := True;

Gruss Horst


Das kann so eben nicht functionieren.
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Di 25.04.06 09:18 
Ja, weil TThread auch kein Bezeichner ist, sondern ein Klassen-Name.

Ich gehe nun davon aus, dass Horst_H das mit Absicht gemacht hat, um zu zeigen, dass die Objekt-Klasse TThread die Methode (!!!) Terminate() unterstützt (oder Terminated auf true setzen) und die Eigenschaft FreeOnTerminate, dass man auf true setzt, was dann den Thread nach Terminierung automatisch frei gibt.

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 25.04.06 09:24 
Das Problem dabei ist aber, dass ein MyThread.Terminate den Thread nicht terminiert, sondern nur einen Flag setzt, welches bewirkt, dass der Thread bei der nächsten Gelegenheit beendet wird. Wenn der Thread aber hängt, und dieses Flag nicht abrufen kann, wird der Thread nicht beendet.

_________________
We are, we were and will not be.
sky21 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 141

W7
D2010, XE2
BeitragVerfasst: Di 25.04.06 10:04 
user profile iconGausi hat folgendes geschrieben:
Das Problem dabei ist aber, dass ein MyThread.Terminate den Thread nicht terminiert, sondern nur einen Flag setzt, welches bewirkt, dass der Thread bei der nächsten Gelegenheit beendet wird. Wenn der Thread aber hängt, und dieses Flag nicht abrufen kann, wird der Thread nicht beendet.


Ja richtig, ich meine eben genau das mit meiner Aussage "Das kann so nicht gehen". 'TThread' war ja wohl nur zur illustration. Eben, ich muss den Thread von aussen abschiessen können, wenn dieser eine nicht-mehr-zuckende function aufgerufen hat. Ausser, jemand kennt eine bessere Lösung, wie ich TIdFTP.Connect so aufrufen kann, dass man diese anderwärtig abschiessen kann.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Di 25.04.06 11:42 
Man kann Threads mit TerminateThread abschießen, dabei wird der vom Thread belegte Speicher aber nicht freigegeben. Lies mal lieber die Win32-Hilfe dazu...
user profile iconDie Win32.Online Hilfe hat folgendes geschrieben:

TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:

· If the target thread owns a critical section, the critical section will not be released.
· If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
· If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.

_________________
Na denn, dann. Bis dann, denn.