Thanks Malcom.

Have included the code as sent and will test it out.
If it works I may be an idea to add to Torry's Hints pages. As I 
expect there will be many others needing this code fragment.

thanks again

Richard

> > A background task is causing problems on notebooks with XP-SP2. 
The application
> > is developed using D7. It seems that the notebook is shutting down 
even though
> > the application is busy processing a background thread.
> 
> You can try this:
> 
> const
>    ES_SYSTEM_REQUIRED  =1;
>    ES_DISPLAY_REQUIRED =2;
>    ES_USER_PRESENT     =4;
>    ES_CONTINUOUS       =$80000000;
>    KernelDLL='kernel32.dll';
> type
>    EXECUTION_STATE=DWORD;
> var
>    KernelHandle:Thandle;
>    SetThreadExecutionState: procedure(ESFlags:EXECUTION_STATE); 
stdcall;
> begin
>    KernelHandle:=LoadLibrary(KernelDLL);
>    if KernelHandle>=32 then begin{success}
>      SetThreadExecutionState:=
>                  GetProcAddress
(KernelHandle,'SetThreadExecutionState');
>      if @SetThreadExecutionState=nil then
>        RaiseLastOSError;
>      SetThreadExecutionState(ES_SYSTEM_REQUIRED or ES_CONTINUOUS);
>      FreeLibrary(KernelHandle);
>      SetThreadPriority(HandleOfThread,THREAD_PRIORITY_HIGHEST);
>    end
>    else
>      MessageDlg('Error: could not find '+KernelDLL,mtError,[mbOk],0);
> end;
> 
> Although you might reconsider the call to SetThreadPriority; its 
> probably not necessary.
> 
> -malcolm
> 
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk
> 
> 

-- 


__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to