Einzelnen Beitrag anzeigen

asdfg
(Gast)

n/a Beiträge
 
#9

Re: [Threads] auf Suspended warten

  Alt 20. Nov 2005, 16:26
Zitat von Der_Unwissende:
Rechenzeit wird mit Application.ProcessMessages freigegeben.

Aber bist du dir sicher, dass du auf ein Suspend warten möchtest? Sollte Suspend nicht durch den Hauptthread gesetzt werden um den Thread zu unterbrechen? Wenn du jedenfalls auf irgendwas wartest gibt es folgende Möglichkeiten

Delphi-Quellcode:
// Wartezeit ms warten und währenddessen Rechenzeit freigeben

var ticks : Int64;
begin
  ticks := GetTickCount;
  while not (GetTickCount - time) >= Wartezeit do
    begin
      Application.ProcessMessages;
    end;
end;

// Warten bis irgendeine Bedingung erfüllt ist
begin
  while not Bedingung do
    begin
      Application.ProcessMessages;
    end;
end
http://www.delphicorner.f9.co.uk/articles/op1.htm
Zitat:
it's totally inefficient. While Application.ProcessMessages allows a program to continue to receive and process messages it receives, it still eats up CPU time because all it's doing is yielding temporarily, then going back to its original state, meaning it constantly activates and deactives.
http://www.ibrtses.com/delphi/threads.html
Zitat:
Beside waiting for a TEvent, there are WaitForSingleObject and WaitforMultipleObjects

WaitForSingleObject allows waiting for a variety of events : ChangeNotification, ConsoleInput, Event, Mutex, Process termination, Semaphore, Thread termination, Timer.
WaitforSingleObject(Handle_of_the_object,timeout);
WaitforMultipleObjects can wait for a number of events at the same time. It is what the ADA 'select' statement does.
WaitForMultipleObjects(NumberOfEvents,PtrToHandleA rray,WaitAll,timeout);
man kann das doch mit WaitForSingleObject machen. dafür benötigt man einen Timeout. Kann man das Timeout berechnen oder deaktiveren
  Mit Zitat antworten Zitat