Dear Friends,
I have developed a multithreaded application for Windows
using VisualCafe.
There are two threads in this application.
The main thread is associated with the main frame
and it is responsible for user interactions.
The other thread is used to communicate with hardware;
it executes commands that require some time to be completed.
The main thread starts the second thread and
waits till the second thread is completed :
{
Thread mainThread = Thread.currentThread();
secondThread cfThread = new SecondThread();
cfThread.start();
while (! SecondThreadStatus.Finished)
{
try
{
// ProcessMessages(); !!!!! ?????????
mainThread.sleep(10);
}
catch (InterruptedException e) {
}
}
}
Class SecondThreadStatus contains static variable Finished
and is used to check the status of the second thread.
The problem is that I do not know how to process Windows
messages. As a result, this application does not respond
to user commands (pressing buttons etc) after the second
thread is started. I need the code for procedure
ProcessMessages.
I have developed similar applications using Delphi that work well. The related procedure looks like this :
procedure WaitForCompletion;
begin
while not Finished do begin
Application.ProcessMessages;
Sleep(100);
end;
end;
/* -------------------------------------------------- */
The code for TApplication.ProcessMessages (unit Forms)
function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
var
Handled: Boolean;
begin
Result := False;
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
begin
Result := True;
if Msg.Message <> WM_QUIT then
begin
Handled := False;
if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
if not IsHintMsg(Msg) and not Handled and
not IsMDIMsg(Msg) and
not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else
FTerminate := True;
end;
end;
procedure TApplication.ProcessMessages;
var
Msg: TMsg;
begin
while ProcessMessage(Msg) do {loop};
end;
Thank you in advance for your advice,
Dmitri
I have developed a multithreaded application for Windows
using VisualCafe.
There are two threads in this application.
The main thread is associated with the main frame
and it is responsible for user interactions.
The other thread is used to communicate with hardware;
it executes commands that require some time to be completed.
The main thread starts the second thread and
waits till the second thread is completed :
{
Thread mainThread = Thread.currentThread();
secondThread cfThread = new SecondThread();
cfThread.start();
while (! SecondThreadStatus.Finished)
{
try
{
// ProcessMessages(); !!!!! ?????????
mainThread.sleep(10);
}
catch (InterruptedException e) {
}
}
}
Class SecondThreadStatus contains static variable Finished
and is used to check the status of the second thread.
The problem is that I do not know how to process Windows
messages. As a result, this application does not respond
to user commands (pressing buttons etc) after the second
thread is started. I need the code for procedure
ProcessMessages.
I have developed similar applications using Delphi that work well. The related procedure looks like this :
procedure WaitForCompletion;
begin
while not Finished do begin
Application.ProcessMessages;
Sleep(100);
end;
end;
/* -------------------------------------------------- */
The code for TApplication.ProcessMessages (unit Forms)
function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
var
Handled: Boolean;
begin
Result := False;
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
begin
Result := True;
if Msg.Message <> WM_QUIT then
begin
Handled := False;
if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
if not IsHintMsg(Msg) and not Handled and
not IsMDIMsg(Msg) and
not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else
FTerminate := True;
end;
end;
procedure TApplication.ProcessMessages;
var
Msg: TMsg;
begin
while ProcessMessage(Msg) do {loop};
end;
Thank you in advance for your advice,
Dmitri