PostThreadMessage wird sicherlich noch an anderen Stellen aufgerufen, da dies ja eine Nachricht an ein bestimmten
Thread ist (mit Angabe des ThreadHandles wird PostThreadMessage aufgerufen).
ITask habe ich noch nie benutzt und wüsste jetzt auch nicht, warum man das umstellen sollte?! Vor- und Nachteile?
@Kas Ob.
Ich versuche nur auf ein Bruchteil zu antworten, da meiner Meinung nach Fragen dabei sind, die nichts damit zu tun haben.
Die IdUDPServer Komponente ruft das OnUDPRead Event auf. Dort werden die Nachrichten an die entsprechenden Clients-Threads weitergeleitet.
Der Aufruf des OnUDPRead Events erfolgt NICHT in der
VCL.
Geprüft durch Abfrage
if (MainThreadID <> GetCurrentThreadID) then
Die
Threads empfangen die Nachrichten und machen damit etwas.
Auf das erfolgt nicht in der
VCL.
Ich sage auch nicht, dass es am UDP hängt! Ich bekomme es nur damit nachgestellt. Es hängt definitiv die
VCL (siehe IdleEvent). Eventuell ist auch etwas anderes Schuld. Synchronize Aufrufe sind KEINE im Programm.
CPU Auslastung vom MainThread ist laut Prozessexplorer 0.05, während die Anwendung hängt!
Mein Rechner hat 24 Kerne, eine volle Auslastung wären demnach 4%, welche ich aber NICHT habe.
Kleine Korrektur, es ist nicht "WaitForsingleObject" sondern "MsgWaitForMultipleObjects".
Wenn der Returnwert = WAIT_OBJECT_0 ist, wird die Thread-Queue abgearbeitet mit
while PeekMessage(MessageData, 0, 0, 0, PM_REMOVE) do
Ja, alle Variablen für die Zeitmessung sind lokal. Ich hatte TC2 vergessen mit in dem Codeschnipsel zu schreiben. Ist ja nur ein Ausschnitt des Codes und da hatte ich TC2 übersehen.
Now this is confusing even more,
If you are using OnUDPRead and it is running in background
thread context then what this loop suppose to serve ?
Delphi-Quellcode:
while not Terminated do
begin
//here a signal is sent via WaitForSingleObject and if the timeout occurs (=250ms), the cyclic call below is made
if WaitForsingleObject(Something, 250, xxxx) = WAIT_OBJECT_0 do
begin
end ;
end ;
Where is running ? and it is hugging something and should be removed, yes altogether, remove it.
Just take a step back and look at the big picture and simplify the whole thing, and don't answer my question, and trying to explain to me, and yes, imagine you are trying to explain the whole thing and i am %100 sure you will figure the miss use of over engineering you are doing.
here a simple approach :
OnUDPRead fired, we read, we are in background
thread so no synchronization call of any sort is needed, we process and we exit,
no looping no waiting for msg or anything inside these events. you need to log something then use a faster approach and don't want on disk or UI updates, use PostMessage and that is it.