我需要记录一些数据,并且最好使用线程复制文件,但是使用下面的代码,但它只是冻结我的应用程序.
如果我正确理解整个XE7 Parallell库TThread.Queue并且TThread.Synchronize应该与主线程同步,但在我的情况下整个应用程序冻结.
我究竟做错了什么?
procedure TCopyDeviceContent.StartCopy;
var
OK: boolean;
begin
OK := false;
// showmessage('fFiles.Count = '+inttostr(fFiles.Count));
if fFiles.Count = 0 then
begin
NotifyDone;
exit;
end;
TParallel.For(0, fFiles.Count-1,
procedure (Value: Integer)
begin
TThread.Queue(TThread.CurrentThread, //Here is where it freezes
procedure
begin
Log('Setting fCurrentFile to '+fFiles.Strings[value]);
end
);
sleep(1000);
fCurrentFile := fFiles.Strings[value];
Log('Triggering fOnBeforeProcess');
if assigned(fOnBeforeProcess) then fOnBeforeProcess(self);
Log('Does file exist?');
if FileExists(fFiles.Strings[value]) = true then
begin
Log('Yes!');
Log('Trying to copy file to Windows temp folder.');
try
TFile.Copy(fFiles.Strings[value], …Run Code Online (Sandbox Code Playgroud)