【发布时间】:2012-09-27 13:23:07
【问题描述】:
我正在寻找一种快速替代 Delphi 中的 CreateProcess 的方法,以在 exe 中执行某些计算,包括 XML 中的几个返回值。 目前,我正在调用带有某些参数的 C#-exe。其中一个电话大约需要。 0.5 秒 - 这方式太昂贵了,因为这个 exe 需要调用几百次(不幸的是迭代调用,即多线程不会加快工作速度)。
我当前的代码如下所示(在 StackOverflow 上找到了获取 exe somwhere 的控制台输出的解决方案)。
IsExecutable := CreateProcess(
nil,
PChar(WorkDir + Exe + CommandLine),
nil,
nil,
True,
HIGH_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInformation);
CloseHandle(StdOutPipeWrite);
if IsExecutable then
try
repeat
WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil);
if BytesRead > 0 then
begin
Buffer[BytesRead] := #0;
Result := Result + Buffer;
end;
until not WasOK or (BytesRead = 0);
WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
finally
CloseHandle(ProcessInformation.hThread);
CloseHandle(ProcessInformation.hProcess);
end
顺便说一句,我不是很好的 Delphi - 实际上,我有点像“我不知道自己在做什么”狗模因...
【问题讨论】:
标签: performance delphi exe pascal createprocess