Board index » delphi » multitasking with Delphi?

multitasking with Delphi?

I'm new to this group but here goes...

It bothers me that when my Delphi application starts a routine
that takes time (like reading the contents of 440 files) nothing
else responds before the routine is completed. Is it necessary
for me to program multitasking explicitely? What I'm looking for
is the functionality of Netscape where you can cancel the routine
in mid way.

Is there a FAQ for this group? How do I get it?

Sincerely,
Marc de Oliveira

 

Re:multitasking with Delphi?


In article: <1995Sep11.065155.4...@esa.uucp>  m...@esa.uucp (Marc de Oliveira) writes:

Quote

> I'm new to this group but here goes...

> It bothers me that when my Delphi application starts a routine
> that takes time (like reading the contents of 440 files) nothing
> else responds before the routine is completed. Is it necessary
> for me to program multitasking explicitely? What I'm looking for
> is the functionality of Netscape where you can cancel the routine
> in mid way.

Yes, you are probably going to have to program a bit of multi tasking into your loop. Windows 3.1 is
not 'preemptive' (W95 is, unless you are runnning 167 bit apps). The following is some code from Delphi
Unleashed (well worth the money) which you call from inside your loop. This gives windows the chance to
respond to other things that are happening:

procedure YieldToOthers;
var
  Msg : TMsg;
begin
  while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
    if (Msg.Message = WM_QUIT) then begin
      exit;
    end;
    TranslateMessage(Msg);
    DispatchMessage(Msg);
  end;
end;

use it like:

for l := 0 to a verybignumber do begin

    lines of code to do something;
    YieldToOthers;
end;

--
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Russell Weetch
http://www.ukindex.co.uk/
** HAVE YOU REGISTERED YOUR WEB SITE? **
'quite exciting this computer magic'
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Re:multitasking with Delphi?


Quote
Russell Weetch <Russ...@weetch.demon.co.uk> wrote:
>In article: <1995Sep11.065155.4...@esa.uucp>  m...@esa.uucp (Marc de Oliveira) writes:

>> I'm new to this group but here goes...

>> It bothers me that when my Delphi application starts a routine
>> that takes time (like reading the contents of 440 files) nothing
>> else responds before the routine is completed. Is it necessary
>> for me to program multitasking explicitely? What I'm looking for
>> is the functionality of Netscape where you can cancel the routine
>> in mid way.

>Yes, you are probably going to have to program a bit of multi tasking into your loop. Windows 3.1 is
>not 'preemptive' (W95 is, unless you are runnning 167 bit apps). The following is some code from Delphi
>Unleashed (well worth the money) which you call from inside your loop. This gives windows the chance to
>respond to other things that are happening:

>procedure YieldToOthers;
>var
>  Msg : TMsg;
>begin
>  while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
>    if (Msg.Message = WM_QUIT) then begin
>      exit;
>    end;
>    TranslateMessage(Msg);
>    DispatchMessage(Msg);
>  end;
>end;

>use it like:

>for l := 0 to a verybignumber do begin

>    lines of code to do something;
>    YieldToOthers;
>end;

You don't have to write your own "YieldToOthers" function... Delphi has one built-in
for you to use; just call Application.ProcessMessages.

     -Steve Teixeira
      steix...@borland.com

Re:multitasking with Delphi?


In article <396393263...@weetch.demon.co.uk>,
   Russell Weetch <Russ...@weetch.demon.co.uk> wrote:

Quote
>procedure YieldToOthers;
>var
>  Msg : TMsg;
>begin
>  while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
>    if (Msg.Message = WM_QUIT) then begin
>      exit;
>    end;
>    TranslateMessage(Msg);
>    DispatchMessage(Msg);
>  end;
>end;

Um, doesn't Application.ProcessMessages work as well, and isn't it quicker &
easier?  From the help:

ProcessMessages Method

Example

Applies to

TApplication component

Declaration

procedure ProcessMessages;

Description

The ProcessMessages method interrupts the execution of your application so
that Windows can respond to events. For example, the user might want to move a
form on the screen while your application is doing some complex processing
that would ordinarily prevent Windows from responding to keyboard or mouse
events. By calling ProcessMessages, your application permits Windows to
process these events at the time ProcessMessages is called. The
ProcessMessages method cycles the Windows message loop until it is empty and
then returns control to your application.

Re:multitasking with Delphi?


Quote
In article <396393263...@weetch.demon.co.uk>, Russ...@weetch.demon.co.uk wrote:
> procedure YieldToOthers;
> var
>   Msg : TMsg;
> begin
>   while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
>     if (Msg.Message = WM_QUIT) then begin
>       exit;
>     end;
>     TranslateMessage(Msg);
>     DispatchMessage(Msg);
>   end;
> end;

This is the most inexcusable error in Delphi Unleashed.  It looks like the
author was working with an old beta or something.  There is an
Application.ProcessMessages which is essentially the same as his
YieldToOthers procedure.  Use that instead.

Tom

Re:multitasking with Delphi?


Quote
Steve Teixeira <steix...@borland.com> writes:
>Russell Weetch <Russ...@weetch.demon.co.uk> wrote:
>>In article: <1995Sep11.065155.4...@esa.uucp>  m...@esa.uucp (Marc de Oliveira) writes:

>>> I'm new to this group but here goes...

>>> It bothers me that when my Delphi application starts a routine
>>> that takes time (like reading the contents of 440 files) nothing
>>> else responds before the routine is completed. Is it necessary
>>> for me to program multitasking explicitely? What I'm looking for
>>> is the functionality of Netscape where you can cancel the routine
>>> in mid way.

>>Yes, you are probably going to have to program a bit of multi tasking into your loop. Windows 3.1 is
>>not 'preemptive' (W95 is, unless you are runnning 167 bit apps). The following is some code from Delphi
>>Unleashed (well worth the money) which you call from inside your loop. This gives windows the chance to
>>respond to other things that are happening:

>>procedure YieldToOthers;
>>var
[..]

>You don't have to write your own "YieldToOthers" function... Delphi has one built-in
>for you to use; just call Application.ProcessMessages.
>     -Steve Teixeira
>      steix...@borland.com

I have a question in the same line :
When using the operation Seek(), to seek almost to the end of a file on
a network (without reading!), I
sometimes experience very long delays, eg. 45 sec. for a 10 Mb file. Since
Seek is one operation, this looks the entire system.
My question is ;
Should I rewrite my code to use TFileStreams, instead of a file,
Is it a network problem only? (I havent experienced it with local drives),
Or what?

I can add, that this problem is always occuring in win95, but only sometimes
in 3.11

Mads Dydensborg

Other Threads