Board index » delphi » Monitoring directories

Monitoring directories

I'm trying to write a program that monitors a file and takes action when
a file of suitable type appears. Whilst this isn't very difficult, I
want to make the program more efficient by only 'looking' at the folder
every 5 seconds or so. While the program is running currently it uses a
large amount of CPU time (usually all that is available). Is there a way
to make an application 'sleep' for x amount of time?

--

Martin Brooks - Systems Administrator
=====================================
Image Data Systems (UK) Ltd
82-84 Clerkenwell Road
London
EC1M 5RJ

  T: 0171 336 7942
  F: 0171 336 7943
  E: mar...@image-data.com
UIN: 2178117

- Computers make very fast, very accurate mistakes. -

 

Re:Monitoring directories


On Thu, 17 Jul 1997 11:18:06 +0100, Martin Brooks

Quote
<mar...@image-data.com> wrote:
>I'm trying to write a program that monitors a file and takes action when
>a file of suitable type appears. Whilst this isn't very difficult, I
>want to make the program more efficient by only 'looking' at the folder
>every 5 seconds or so. While the program is running currently it uses a
>large amount of CPU time (usually all that is available). Is there a way
>to make an application 'sleep' for x amount of time?

>--

>Martin Brooks - Systems Administrator
>=====================================
>Image Data Systems (UK) Ltd
>82-84 Clerkenwell Road
>London
>EC1M 5RJ

>  T: 0171 336 7942
>  F: 0171 336 7943
>  E: mar...@image-data.com
>UIN: 2178117

>- Computers make very fast, very accurate mistakes. -

Hi Martin.  I think the "Timer" component would be the perfect answer.
Check it out.  In it you can define the timing interval and call your
directory scanning functions.

Happy coding !
do...@ime.net[spam buster - remove this trailer]

Re:Monitoring directories


Quote
Martin Brooks wrote:

> I'm trying to write a program that monitors a file and takes action when
> a file of suitable type appears. Whilst this isn't very difficult, I
> want to make the program more efficient by only 'looking' at the folder
> every 5 seconds or so. While the program is running currently it uses a
> large amount of CPU time (usually all that is available). Is there a way
> to make an application 'sleep' for x amount of time?

If it's a Win32 application there's a Win32 API function, Sleep, that
does just what you want. However, for both Win16 and Win32 you can use a
TTimer component with the delay set to 5000 and do the checking in the
OnTimer event handler.

Chris Jobson

Re:Monitoring directories


 In a nutshell...

Use "CreateEvent" (specify flag for watching folder or file changes), then
"WaitForSingleObject"...

very efficient.

Martin Brooks wrote in article <33CDF15D.98A34...@image-data.com>...

Quote
>I'm trying to write a program that monitors a file and takes action when
>a file of suitable type appears. Whilst this isn't very difficult, I
>want to make the program more efficient by only 'looking' at the folder
>every 5 seconds or so. While the program is running currently it uses a
>large amount of CPU time (usually all that is available). Is there a way
>to make an application 'sleep' for x amount of time?

>--

>Martin Brooks - Systems Administrator
>=====================================
>Image Data Systems (UK) Ltd
>82-84 Clerkenwell Road
>London
>EC1M 5RJ

>  T: 0171 336 7942
>  F: 0171 336 7943
>  E: mar...@image-data.com
>UIN: 2178117

>- Computers make very fast, very accurate mistakes. -

Other Threads