about thread |
尚未結案
|
asan
一般會員 ![]() ![]() 發表:5 回覆:8 積分:2 註冊:2003-05-12 發送簡訊給我 |
file2 := file;
a := 0; while (FileExists( path '\' file2) = true) or (FileExists( path '\' file2 '.td!') = true) do
begin
a := a 1;
file2 := inttostr(A) '_' file ;
end; try
ForceDirectories(path);
fs := TFileStream.Create(path '\' file2 '.td!',fmCreate); except
file_err := 1;
end;
有一個 thread
他會檢查是否有相同的檔名
如果有就給他一個流水號
如 a
a_1 , a_2,a_3
但是因為 thread 是一次開五個
所以有些這個檢查程序會出問題
不知道開如何解決
|
Stallion
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
var LockThis:TCriticalSection; // global variable, prevent other thread enter at same time LockThis.Acquire; file2 := file; a := 0; while (FileExists( path '\' file2) = true) or (FileExists( path '\' file2 '.td!') = true) do begin a := a 1; file2 := inttostr(A) '_' file ; end; try try ForceDirectories(path); fs := TFileStream.Create(path '\' file2 '.td!',fmCreate); except file_err := 1; end; finally LockThis.Release; end;------------------- 學,然後知不足。 發表人 - stallion 於 2005/07/27 01:08:03 |
ppp
一般會員 ![]() ![]() 發表:1 回覆:3 積分:0 註冊:2004-03-16 發送簡訊給我 |
我剛好也有這個困擾 :) Stallion的程式我又加上 LockThis := TCriticalSection.Create;
這樣才能跑 如果我一次開 10個 thread 那應該會做出 10 個檔名, 例如 test, 1_test, 2_test, 3_test... 9_test 但是似乎沒有用. 檔案只會出現 test , 1_test , 2_test 幾個
其他 thread 還是沒把檔案給建立出來, 我還缺了什麼嗎? mythread.excute();
var
LockThis:TCriticalSection; // global variable, prevent other thread enter at same time
a, file_err : integer;
file, file2, path : string; begin LockThis := TCriticalSection.Create;
LockThis.Acquire; file2 := file;
a := 0;
path := 'c:\test'; while (FileExists( path '\' file2) = true) or (FileExists( path '\' file2 '.td!') = true) do
begin
a := a 1;
file2 := inttostr(a) '_' file ;
end;
try
try
ForceDirectories(path);
fs := TFileStream.Create(path '\' file2 '.td!',fmCreate);
except
file_err := 1;
end;
finally
LockThis.Release;
end; end;
|
asan
一般會員 ![]() ![]() 發表:5 回覆:8 積分:2 註冊:2003-05-12 發送簡訊給我 |
|
Stallion
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
|
ppp
一般會員 ![]() ![]() 發表:1 回覆:3 積分:0 註冊:2004-03-16 發送簡訊給我 |
|
asan
一般會員 ![]() ![]() 發表:5 回覆:8 積分:2 註冊:2003-05-12 發送簡訊給我 |
|
Ktop_Robot
站務副站長 ![]() ![]() 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |