From: "Antonio" Subject: Re: Waiting For A File Date: 05 Nov 2000 00:00:00 GMT Message-ID: <8u265g$8751@bornews.borland.com> References: <3A0315F3.B5758F53@documentprocessing.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.delphi.objectpascal Christopher, the following function consumes very litte CPU while waiting for a file to be created: function WaitForFile(FileName: String):Boolean; // Wait for a file to be created // Tracks the directory were the file will be created // Returns true if file exists, false on error Var WaitHandle: THandle; begin Result:=False; // Let's assumed we failed WaitHandle:= FindFirstChangeNotification( PChar(ExtractFilePath(FileName)), False, FILE_NOTIFY_CHANGE_FILE_NAME ); If (INVALID_HANDLE_VALUE = WaitHandle) then begin // The path to the file does not exists Exit; end; repeat if WaitForSingleObject(WaitHandle, INFINITE) = WAIT_OBJECT_0 then begin // something happenned in the directory if FileExists(FileName) then begin result:=True; Break; // my file has been created, exit end; // my file is not there, keep on if Not FindNextChangeNotification(WaitHandle) then begin // something happened to the directory, // may be, it was deleted Break; end; end; Until False; FindCloseChangeNotification(WaitHandle); end; Regards, Antonio "Christopher Pall" escribió en el mensaje news:3A0315F3.B5758F53@documentprocessing.com... > Does anyone have code that will wait for a file to be created? In particular I'm > trying to come up with code that has pretty much a 0% processor usage. > > -- > Chris