delphi SetPriorityClass 设置当前程序的优先级  
官方Delphi 学习QQ群: 682628230(三千人)\n
频道

delphi SetPriorityClass 设置当前程序的优先级


在一些特定的情况下,我们需要设定我们程序的优先级比较高,这样能保证在程序的运行过程中,程序几乎不用考虑在被CPU执行时不被其他程序意外抢占。

在winbase.h中是这样定义的:

1.函数定义:

WINBASEAPI
BOOL
WINAPI
SetPriorityClass(
    __in HANDLE hProcess,
    __in DWORD dwPriorityClass
    );

第一个参数为进程的句柄,第二个参数为优先级的级别。
2.优先级定义:
#define NORMAL_PRIORITY_CLASS         0x00000020
#define IDLE_PRIORITY_CLASS                0x00000040
#define HIGH_PRIORITY_CLASS               0x00000080

如果我们需要设置自己的程序为最高优先级,我们可以在程序启动后调用:

SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
————————————————
delphi 用法:

{ 调整进程 }
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);

 { 调整进程、线程级别到最高级别 }
  SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.044252872467041 seconds