多线程不是第一次写了,主要是照顾用户使用的方便,不会让主窗口停顿
这次用到了THashedStringList以及TStringList处理上万条文本行的搜索和更新,也是利用多线程,主窗口只是个进度条走动而已
但是当线程执行以后,主窗口不能拖动也不能获得焦点,只能看到进度条在走动,而其除了主菜单还能显示出来,其他的控件都消失了。等线程执行完毕了才又出来,好像是重新绘制了窗口。
我在线程里面也用了Synchronize来同步这个过程,但是没有任何效果。
请问各位有没有遇到类似的问题?我错在哪里?
下面是线程中的过程,而且我发现处理小数据量的时候一点问题没有,或许是太快感觉不到。
var
TstringTmp01,TstringTmp02:THashedStringList;//
intTmp01,intTmp02,intIndex:integer;//计数器
StrSource,StrCheck:string; //源字符和对比字符
int_Temp:integer;
begin
TstringTmp01:=THashedStringList.Create;
TstringTmp02:=THashedStringList.Create;
TstringTmp01.LoadFromFile('20080227123152.txt');
label1.Caption:=inttostr(TstringTmp01.Count);
TstringTmp01.Sort;
// TstringTmp01.Sorted:=true;
int_Temp:=0;
for intTMp01 := 0 to TstringTmp01.Count-1 do begin
strSource:=TstringTmp01[intTmp01];
if (length(strSource)>0) then begin
while (TstringTmp01.Find(strSource,intTmp02))do
TstringTmp01[intTmp02]:='';
if not TstringTmp02.Find(strSource,int_Temp) then TstringTmp02.Add(strSource);
end;
end;
for intTmp02 := 0 to TstringTmp02.Count - 1 do
memo2.Lines.Add(TstringTmp02[intTmp02]);
TstringTmp01.Free;
TstringTmp02.Free;
这次用到了THashedStringList以及TStringList处理上万条文本行的搜索和更新,也是利用多线程,主窗口只是个进度条走动而已
但是当线程执行以后,主窗口不能拖动也不能获得焦点,只能看到进度条在走动,而其除了主菜单还能显示出来,其他的控件都消失了。等线程执行完毕了才又出来,好像是重新绘制了窗口。
我在线程里面也用了Synchronize来同步这个过程,但是没有任何效果。
请问各位有没有遇到类似的问题?我错在哪里?
下面是线程中的过程,而且我发现处理小数据量的时候一点问题没有,或许是太快感觉不到。
var
TstringTmp01,TstringTmp02:THashedStringList;//
intTmp01,intTmp02,intIndex:integer;//计数器
StrSource,StrCheck:string; //源字符和对比字符
int_Temp:integer;
begin
TstringTmp01:=THashedStringList.Create;
TstringTmp02:=THashedStringList.Create;
TstringTmp01.LoadFromFile('20080227123152.txt');
label1.Caption:=inttostr(TstringTmp01.Count);
TstringTmp01.Sort;
// TstringTmp01.Sorted:=true;
int_Temp:=0;
for intTMp01 := 0 to TstringTmp01.Count-1 do begin
strSource:=TstringTmp01[intTmp01];
if (length(strSource)>0) then begin
while (TstringTmp01.Find(strSource,intTmp02))do
TstringTmp01[intTmp02]:='';
if not TstringTmp02.Find(strSource,int_Temp) then TstringTmp02.Add(strSource);
end;
end;
for intTmp02 := 0 to TstringTmp02.Count - 1 do
memo2.Lines.Add(TstringTmp02[intTmp02]);
TstringTmp01.Free;
TstringTmp02.Free;
for intTmp02 := 0 to TstringTmp02.Count - 1 do
memo2.Lines.Add(TstringTmp02[intTmp02]);
这几行放在一个procedure里,然后用Synchronize来执行这个procedure。