Autor Beitrag
sango
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 236

WinXP Home
Delphi 2005 Pro
BeitragVerfasst: Mo 10.10.05 21:37 
hi,

ich hab ein problem, ich starte nen thread, in diesem läuft ne endlosschleife, diese bringt das ding aber dazu 99% zu beanspruchen. Hat jemand ne lösung oder ne andere idee? reicht wenn das alle 100-200 oder sogar 500 ms läuft.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
procedure THookThread.execute;
var i:integer;
  warwas:boolean;
begin
  while true do
  begin

  //  blablabla ich tu was....
                  Application.ProcessMessages;
          wait(1000);
  end;
      
end;

procedure THookThread.Wait(time: word);
var Start: Integer;
begin
  Start:=GetTickCount;
  while GetTickCount-Start <= time do
    application.ProcessMessages;
end;

constructor THookThread.create;
begin
  inherited create(true);
  freeOnTerminate := true;
end;


so funktioniert auch alles wunderbar, nur eben mit zu hoher cpu last.

what to do????

mfg Seba

_________________
Never read the Off-Topic
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Mo 10.10.05 21:41 
Warum eine eigene Prozedur (wait) schreiben?
Und in einem Thread musst du sowieso nicht Application.ProzessMessages aufrufen!

Ersetze
ausblenden Delphi-Quelltext
1:
Wait(1000);					

einfach durch
ausblenden Delphi-Quelltext
1:
Sleep(1000);					


Damit sollte die Prozessorlast auf annähernd 0% (für dein Programm) sinken.

Alstar
sango Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 236

WinXP Home
Delphi 2005 Pro
BeitragVerfasst: Mo 10.10.05 21:47 
ok hat sich erledigt, war nen begin end; falsch gesetzt. sorry my fault.

_________________
Never read the Off-Topic