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

Вниз

PeekMessage   Найти похожие ветки 

 
Sergey   (2003-05-13 21:07) [0]

Так... у мя вопросик... как использовать енту функцию...

Вот у меня например ожидание какого-то момента

repeat
sleep(500)
until ...

Что и как надо сделать, чтобы в это время программа не "висела"...?


 
Palladin ©   (2003-05-13 21:17) [1]

не использовать sleep


 
Думкин ©   (2003-05-14 06:52) [2]

GetTickCount
Application.ProcessMessages


 
Sergey   (2003-05-14 11:20) [3]

Palladin

>не использовать sleep

???
ну допустим...а как тогда мне например сделать ожидание запуска сервиса в течении 20 секунд без нагрузка на проц?


 
Anatoly Podgoretsky ©   (2003-05-14 11:25) [4]

Sergey (14.05.03 11:20)
sleep в отдельном потоке, правда и sleep не обязателен можно WaitFor*


 
panov ©   (2003-05-14 12:00) [5]

Можно и так примерно:


unit uWaitMoment;

uses classes,windows;

const WM_OPPA=WM_USER+1;

type
TWaitOneMoment = class(TThread)
private
fInterval: Cardinal;
fHandleForm: THandle;
protected
procedure Execute; override;
public
constructor Create(aHandleForm: THandle;aInterval: Cardinal);
end;

implementation

constructor TWaitOneMoment.Create(aHandleForm: THandle;aInterval: Cardinal);
begin
inherited Create(True);
fHandleForm := aHandleForm;
fInterval := aInterval;
FreOnTerminate := True;
Priority := tpTimeCritical;
Resume;
end;

procedure TWaitOneMoment.Execute;
var
SleepInterval: Cardinal;
begin
SleepInterval := 50;
while fInterval>0 do
begin
if fInterval<50 then SleepInterval := fInterval;
if Terminated then Break;
Sleep(SleepInterval);
fInterval := fInterval-SleepInterval;
end;
if fInterval<=0 then PostMessage(fHandleForm,WM_OPPA,0,0);
end;

end.

unit ....

uses uWaitMoment;

TForm1=class...
private
procedure OnWM_OPPA(var msg:TMessage);message WM_OPPA;
...
end;

implementation

procedure TForm1.OnWM_OPPA(var msg:TMessage);
begin
ShowMessage("Дождались наконец-то!");
end;

procedure TForm1.ButtonStartClick(Sender: TObject);
begin
...
TWaitOneMoment.Create(Form1.Handle,20000);
end;

...
end.


 
gek ©   (2003-05-14 12:03) [6]

Не, это понятно.
Но, по-моему WaitFor более приемлем


 
panov ©   (2003-05-14 12:05) [7]

WaitFor заблокирует интерфейс пользователю.


 
gek ©   (2003-05-14 13:46) [8]


> panov © (14.05.03 12:05)
> WaitFor заблокирует интерфейс пользователю.


Честно говоря не встречался. Не знаю...



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

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

Наверх




Память: 0.48 MB
Время: 0.011 c
6-83620
трям
2003-03-26 01:12
2003.05.26
Как узнать в Вин IP адрес?


1-83533
Gremlin
2003-05-12 20:02
2003.05.26
Баги со строками


7-83762
Кот Джин
2003-03-28 14:48
2003.05.26
Как узнать версию Windows?


3-83347
Rocker
2003-04-28 10:34
2003.05.26
как программно ввести пароль при доступе к БД?


14-83708
Sherbacov
2003-05-06 19:50
2003.05.26
Хеш вектор