Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.02.06;
Скачать: CL | DM;

Вниз

Загрузка процессора   Найти похожие ветки 

 
Artem_ ©   (2004-12-21 15:38) [0]

Есть консольная программа. Во время віполнения занимает 100% загрузки ЦП. Может кто порекомендует как исправить?

program pause;

{$APPTYPE CONSOLE}

uses
 SysUtils, Messages, Windows;

var
 i, id: Integer;
 inpHnd: THandle;
 Wr: DWORD;
 Mess: TMsg;
 IR: TInputRecord;

procedure OnTimer;
var
 c: _COORD;
 OutHwnd: THandle;
 Buf: Array[0..28] of Char;
 str1, str2: String;
 j, m, s: Integer;
begin
OutHwnd := GetStdHandle(STD_OUTPUT_HANDLE);
c.X := 1; c.Y := 1;
m := i div 60;
s := i mod 60;
str2 := IntToStr(m);
while Length(str2)<2 do str2 := " " + str2;
str1 := "*** "+Chr(143)+" &#227;§  " + str2 + " ¬&#168;"+Chr(173)+". ";
str2 := IntToStr(s);
while Length(str2)<2 do str2 := " " + str2;
str1 := str1 + str2 + " &#225;"+Chr(165)+"&#170;. ***";
Move(str1[1], Buf, 29);
j := GetConsoleOutputCP;
SetConsoleOutputCP(1251);
WriteConsoleOutputCharacter(OutHwnd, @Buf, 29, c, wr);
FillConsoleOutputAttribute(OutHwnd, 15, 10, C, Wr);
c.X := 11; c.Y := 1;
FillConsoleOutputAttribute(OutHwnd, 10, 2, C, Wr);
c.X := 13; c.Y := 1;
FillConsoleOutputAttribute(OutHwnd, 15, 6, C, Wr);
c.X := 19; c.Y := 1;
FillConsoleOutputAttribute(OutHwnd, 10, 2, C, Wr);
c.X := 21; c.Y := 1;
FillConsoleOutputAttribute(OutHwnd, 15, 9, C, Wr);
SetConsoleOutputCP(j);
Dec(i);
if i=0 then begin
 IR.EventType := KEY_EVENT;
 IR.Event.KeyEvent.bKeyDown := True;
 IR.Event.KeyEvent.wVirtualKeyCode := VK_F10; end;
end;

begin
 { TODO -oUser -cConsole Main : Insert code here }
if ParamCount=0
 then Halt(0);
i := StrToInt(Trim(ParamStr(1)))*60;
ID := SetTimer(0, 0, 10000, nil);
InpHnd := GetStdHandle(STD_INPUT_HANDLE);
repeat
 GetNumberOfConsoleInputEvents(InpHnd, Wr);
 if Wr>0 then
 begin
  ReadConsoleInput(InpHnd,IR,1,Wr);
 end;
 if PeekMessage(Mess,0, WM_NULL,WM_APP,PM_NOREMOVE) then begin
  GetMessage(Mess, 0, WM_NULL,WM_APP);
  case Mess.message of
   WM_TIMER: OnTimer;
  end;
 end;
 
until IR.Event.KeyEvent.wVirtualKeyCode = VK_F10;
KillTimer(0,ID);
end.


 
Jay1982 ©   (2004-12-21 15:45) [1]

Попробуй вставить задержку в цикл, Sleep(100), например


 
Jay1982 ©   (2004-12-21 15:46) [2]

Попробуй вставить задержку в цикл, Sleep(100), например


 
Artem_ ©   (2004-12-21 15:48) [3]

Спасибо, помогло :)



Страницы: 1 вся ветка

Текущий архив: 2005.02.06;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.042 c
3-1104840678
Jey
2005-01-04 15:11
2005.02.06
Фильтрация


1-1106230743
Мальцев
2005-01-20 17:19
2005.02.06
Установить фокус


3-1105100620
Erik1
2005-01-07 15:23
2005.02.06
Вопрос к мастерам, возможно востановление флага UpdatesPending?


1-1106220131
BVV
2005-01-20 14:22
2005.02.06
Атрибуты


1-1106143457
Vera
2005-01-19 17:04
2005.02.06
Фиксированная форма