一个通信线程处理程序,在主界面有一个刷新按钮 启动一个timer 来刷新 Listview(用Virtual方法来根系) 来显示 来源IP
程序一开始都没有什么问题,但是运行一段时间 (有时候1天,有时候2天),然后点击下刷新按钮 主界面 假死 无响应了,
但是通信线程还是正常的处理。弄了半个月了还是找不原因。所有实在没法子了,发帖来求助
程序一开始都没有什么问题,但是运行一段时间 (有时候1天,有时候2天),然后点击下刷新按钮 主界面 假死 无响应了,
但是通信线程还是正常的处理。弄了半个月了还是找不原因。所有实在没法子了,发帖来求助
解决方案 »
- 很多delphi高手急于解决的问题?
- fast report 如何在程序运行时进入报表的设计状态?
- 有谁学过<计算机网络>,如此变态的考试题目,不好意思又要麻烦大家了!!
- 怎样自定义消息、使用消息?sendmessage 、postmessage有什么区别?
- RyanGT(笑书神侠) 请进来 我一次只能给100分,没办法,大不了我分5次给了 呵呵,现在是第一个100分
- TDateTime和String 如何让相互转换?急!
- 关天任务栏的右右菜单问题。
- 国庆了,睡了一天觉,无聊,特建一聊天室,有没有和我一样无聊的人,来聊聊天
- 我编写的程序结束的时候用Application.destroy来关闭应用程序 可是在进程中还有 是不是我用错了
- ?????类型转换的问题??
- Twebbrowser在新窗口打开链接的问题
- 把16进制字符串转字符串怎么写算法?
1.优化代码
2.大循环处理item的前后加上 ListView1.Items.BeginUpdate;
//大量数据处理部分
ListView1.Items.EndUpdate
数据量不大,几百条的样子
if not Assigned(Users) then
Exit;
UserSocket := users.ViewUser(Item.Index);
if UserSocket <> nil then
with Item, UserSocket do
begin
if FSocket = INVALID_SOCKET then
begin
if OnLine then
Caption := '断开'
else
Caption := '关闭';
end
else
Caption := '保持';
bug:='594';
SubItems.Add(CurrentAction);
SubItems.Add(FundAccount);
SubItems.Add(UserName);
SubItems.Add(ComeFrom);
SubItems.Add(inttostr(ReqCount));
SubItems.Add(inttostr(ReqBytes));
SubItems.Add(inttostr(AnsBytes));
SubItems.Add(inttostr(LastReqBytes));
SubItems.Add(inttostr(LastAnsBytes));
SubItems.Add(FormatDateTime('hh:nn:ss.zzz', LastReqTime));
SubItems.Add(FormatDateTime('hh:nn:ss.zzz', LastAnsTime));
if LastAnsTime >= LastReqTime then
SubItems.Add(Format('%.3f', [LastAccessTimeCount / 1000]))
else
SubItems.Add('--.---');
SubItems.Add(FormatDateTime('hh:nn:ss.zzz', LoginTime));
SubItems.Add(inttostr(LastCVTType));
SubItems.Add(FromAddress);
end;
刷新按钮进去timer停一下,临出来前再把timer启起来。
try
if not Assigned(Users) then
Exit;
AuxTimer.Enabled := False;
if ListViewThread.Items.Count <> Users.ThreadCache.count then
ListViewThread.Items.Count := Users.ThreadCache.count;
ListViewThread.Refresh;
finally
AuxTimer.Enabled := True;
end;
你为啥要写在onData里面啊
DescriptionUse OnData to customize an item before it is displayed in the list view control. Set the properties of the list item in the event handler so that they appear correctly when the item is drawn.OnData occurs only if OwnerData is true.我还真没在这个事件里写过代码尼
把Timer时间设长些,OnTimer事件中里面加个 Application.ProcessMessages
如果还不行就自己写线程,别用Timer。
//添加的新IP信息先保存在一个StringList中,添加前判断StringList中是否存在,如果存在则不添加.
不如将你的程序改为一有数据就会添加到ListViewThread里边,这样就避免了刷新界面无响应的问题.
2.Timer事件的代码没有问题!
你不加ListViewThread.Refresh;这一句试试看怎么样.
就当不向ListViewThread刷新数据.看是否还有无响应的问题.具体要看程序操作了.程序流程还有代码提供太少了...将可能会出现刷新时界面无响应的问题全部先注释掉测试一下(除必用代码外).