线程不停向窗口发消息导致手动操作窗口时一卡一卡的,
有没有什么解决办法,请高手指点一下

解决方案 »

  1.   

    线程里,sleep,主进程里 Application.ProcessMessage;
      

  2.   

    什么线程,CPU都被它占了当然会卡
      

  3.   

    procedure Mine(var msg:TMSG);message WM_MINE;
    procedure Update(var msg:TMSG);message WM_UPDATE;function MyThreadFun(handle: HWND): Integer; stdcall;
    var
      query_result: IMySQLQuery;
      i,j,n: integer;
    begin
      while query_result.FetchRow do
      begin
        ...
        Sendmessage(handle,WM_MINE,0,0);
        Sendmessage(handle,WM_UPDATE,0,0);
      end;
    end;procedure TForm1.Mine(var msg: TMSG);
    var
      i,v:integer;
    begin
      if dl > 0 then
      begin
        Application.ProcessMessages;
        i:=x+1;
        SimpleGraph1.BeginUpdate;
        while dl > 0 do
        begin
        //bschnumd:=0;
          SimpleGraph1.FindNextObject(i, true, true ,true).Delete;
          dl:=dl-1;
        end;
        linesnum:=0;
        SimpleGraph1.EndUpdate;
      end;
    end;
    procedure TForm1.Update(var msg:TMSG);
    var
      i,z:integer;
      rect:TRect;
    begin
      SimpleGraph1.CommandMode := cmInsertLink;
      if linesnum > 0 then
      begin
        Application.ProcessMessages;
        SimpleGraph1.BeginUpdate;
        z:=x;
        for i:=1 to linesnum do
        begin
          z:=z+1;
          lines[i].id:=z;
          SimpleGraph1.InsertLink(SimpleGraph1.FindNextObject(lines[i].ob1, true, true ,true), SimpleGraph1.FindNextObject(lines[i].ob2, true, true ,true)).TextPosition:=lines[i].ob1;
          z:=z+1;
          lines[i].id2:=z;
          SimpleGraph1.InsertLink(SimpleGraph1.FindNextObject(lines[i].ob2, true, true ,true), SimpleGraph1.FindNextObject(lines[i].ob3, true, true ,true)).TextPosition:=lines[i].ob2;
          SimpleGraph1.FindNextObject(lines[i].id, true, true ,true).Text:=lines[i].name+lines[i].others;
          SimpleGraph1.FindNextObject(lines[i].id2, true, true ,true).Text:=lines[i].name;
       end;
        dl:=z-x;
        SimpleGraph1.EndUpdate;
      end;
      SimpleGraph1.CommandMode := cmEdit;
    end;
      

  4.   

    MyThreadFun(handle: HWND)中有sleep(3000);
      

  5.   

    你在線程裏用了sleep,這倒是沒問題,可問題是你sleep的時間也太長了吧?3000?你這不是讓它卡嗎。這個時間最好是在100之內。你如果想讓它3000,用個循環去做吧。然後還要加上Application.ProcessMessage
      

  6.   

    你的Application.ProcessMessages都还用在循环内。
      

  7.   

    你的Application.ProcessMessages都没用在循环内。