如何从我的程序创建和运行流程,并能够设置流程的优先级?
这是我到目前为止:
const
LOW_PRIORITY = IDLE_PRIORITY_CLASS;
//BELOW_NORMAL_PRIORITY = ???
NORMAL_PRIORITY = NORMAL_PRIORITY_CLASS;
//ABOVE_NORMAL_PRIROTY = ???
HIGH_PRIORITY = HIGH_PRIORITY_CLASS;
REALTIME_PRIORITY = REALTIME_PRIORITY_CLASS;
procedure RunProcess(FileName: string; Priority: Integer);
var
StartInfo: TStartupInfo;
ProcInfo: TProcessInformation;
Done: Boolean;
begin
FillChar(StartInfo,SizeOf(TStartupInfo),#0);
FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
StartInfo.cb := SizeOf(TStartupInfo);
try
Done := CreateProcess(nil, PChar(FileName), nil, nil,False,
CREATE_NEW_PROCESS_GROUP + Priority,
nil, nil, StartInfo, ProcInfo);
if not Done then
MessageDlg('Could not run ' + FileName, mtError, [mbOk], 0);
finally
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
end;
end;
Run Code Online (Sandbox Code Playgroud)
上面的代码的工作原理是我可以设置执行过程的优先级.但请参阅Windows任务管理器下面的图像:

您可以设置更多选项,例如低于正常和高于正常,这也是我想要设置的.通过Windows.pas看,我没有看到这样的价值.
如何使用这些额外参数创建和运行我的流程?
谢谢 :)
我在Windows 10上运行以下代码.
function SingleProcessorMask(const ProcessorIndex: Integer): DWORD_PTR;
begin
Result:= 1; Result:= Result shl (ProcessorIndex); //Make sure it works on processor 33 and up.
end;
procedure TForm2.BtnCreateLookup5x5to3x3UsingSpeculativeExplorationClick(Sender: TObject);
var
ThreadCount: integer;
Threads: TArray<TThread>;
CurrentProcessor: integer;
i,a: integer;
Done: boolean;
begin
ThreadCount:= System.CpuCount;
SetLength(Threads, ThreadCount);
CurrentProcessor:= GetCurrentProcessorNumber;
a:= 0;
for i:= 1 to ThreadCount-1 do begin
Threads[i]:= TThread.CreateAnonymousThread(procedure begin
CreateLookupUsingGridSolver(i, ThreadCount);
end);
Threads[i].FreeOnTerminate:= false;
if (CurrentProcessor = a) then Inc(a); //Skip the current processor.
Inc(a);
//if (SetThreadAffinityMask(Threads[i].handle, SingleProcessorMask(a))) = 0 then RaiseLastOSError; …Run Code Online (Sandbox Code Playgroud)