[SOLVED]App freezing/stalling when button on title bar is clicked lazarus / 34-Windows ---------------------------------------------------------------------- bobix · 2018-08-09 09:26 Can someone tell me why an application stops if button on the title bar of the form is left clicked and held clicked? I mean Minimize, Maximize and Close. Or how to avoid that behaivior. The same application on Linux does not have such problem and nothing stops. To recreate: Run my example project. Click on all 3 buttons. Click on minimize with left mouse button and hold it. All stops. Move the mouse outside the button to avoid minimizing and see that nothing happened in that time. Thank you! ---------------------------------------------------------------------- tetrastes · 2018-08-09 11:26 This is standard behavior for Windows. You may see it in any windows app with something changing, for example Task Manager. ---------------------------------------------------------------------- bobix · 2018-08-09 14:26 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i useswindows; var  PrevWndProc: WNDPROC;   function WndCallback(HWnd: HWND; Msg: UINT; WParam: WParam; LParam: LParam):LRESULT; stdcall;begin  if Msg = WM_NCLBUTTONDOWN then //left down  begin    if WParam=8 then //minimize clicked     begin       Application.Minimize;     end;    if WParam=9 then //maximize clicked     begin      if form1.WindowState=wsNormal then form1.WindowState:=wsMaximized else form1.WindowState:=wsNormal;     end;   if WParam=20 then //close clicked    begin     form1.close;  end;   if WParam=3 then //Menu In Title Bar Application Icon    begin     end;    exit;  end;  if Msg = WM_NCRBUTTONDOWN then //right down  begin    exit;  end;  Result := CallWindowProc(PrevWndProc, HWnd, Msg, WParam, LParam);end; procedure TForm1.FormCreate(Sender: TObject);begin PrevWndProc := Windows.WNDPROC(SetWindowLongPtr(Self.Handle, GWL_WNDPROC, PtrInt(@WndCallback)));end;  Not perfect may be, but works for me ---------------------------------------------------------------------- lucamar · 2018-08-10 01:37 Quote from: bobix on August 09, 2018, 04:26:08 pmNot perfect may be, but works for me "Not perfect", indeed. You're responding to "button down" messages instead of letting Windows process button clicks. It may not matter that much normally but introduces an element of surprise that will annoy users some times (and some users all the times). Best of luck to you  What is happening here (simplyfied a lot) is that as soon as Windows detects a button-down event on the non-client area it stops sending update messages, gets a snapshot of the window and gets ready to start drawing all those nice effects for window-moving, -resizing, etc. The window then stays frozen until the corresponding mouse-up ends the impasse. Nothing you can do about it, except--as shown by boblx--interfere with the process, which is not recomended. ---------------------------------------------------------------------- bobix · 2018-08-10 08:42 I agree There should be better way to avoid hanging the threads. Some developers found a way. Browsers does not freez, media players does not freez, torrents are keep getting downloaded while you are holding mouse button. But as you can see in my example, not just drawing, but everything stops. So me and everyone else here is open for that better solution ---------------------------------------------------------------------- taazz · 2018-08-10 08:49 Quote from: bobix on August 10, 2018, 10:42:07 amI agree There should be better way to avoid hanging the threads. Some developers found a way. Browsers does not freez, media players does not freez, torrents are keep getting downloaded while you are holding mouse button. But as you can see in my example, not just drawing, but everything stops. So me and everyone else here is open for that better solution The only permanent solution is to stop using timers as threads and do a proper multithreading application. By the way you are way way wrong about at least browsers if they use the default windows buttons they do stop updating. test it your self go to a slow loading page press ctrl+r to reload it and click on the minimize button the browser will freeze until you release that mouse button. ---------------------------------------------------------------------- bobix · 2018-08-10 08:52 Quotethe only permanent solution is to stop using timers as threads and do a proper multithreading applicationButton2 in my example is starting a thread. Or i'm not doing it right? ---------------------------------------------------------------------- bobix · 2018-08-10 08:55 QuoteBy the way you are way way wrong about at least browsers if they use the default windows buttons they do stop updating. test it your self go to a slow loading page press ctrl+r to reload it and click on the minimize button the browser will freeze until you release that mouse button. I am opening cnn.com. I'm holding the minimize botton before even my browser connects to their server. In 5 seconds the web page is completely loaded in front of my eyes while i still holding minimize button. Correction. Chrome & IE freez while drawing, but still getting page in background. Firefox & Edge does not freez in any kind. ---------------------------------------------------------------------- taazz · 2018-08-10 09:18 Quote from: bobix on August 10, 2018, 10:55:36 amQuoteBy the way you are way way wrong about at least browsers if they use the default windows buttons they do stop updating. test it your self go to a slow loading page press ctrl+r to reload it and click on the minimize button the browser will freeze until you release that mouse button. I am opening cnn.com. I'm holding the minimize botton before even my browser connects to their server. In 5 seconds the web page is completely loaded in front of my eyes while i still holding minimize button. Correction. Chrome & IE freez while drawing, but still getting page in background. Firefox & Edge does not freez in any kind. firefox freezes while reloading lazarus forums when pressing down the minimize button for me, I'm on windows 7, firefox quantum 60.0 (64-bit) I have never used edge nor I care to sorry. That of course is not the point of my post. You should stop using timers as threading mechanism its unhealthy. ---------------------------------------------------------------------- bobix · 2018-08-10 09:27 Windows 10, Firefox 61 here. Strange. Anyway. Like i said few times, I am using threads! Button1 - simple loop. Button2 - THREAD!!! Button3 - Timer. So I am USING THREADS. Give me an example app with not freezing thread even if its form freezes. ---------------------------------------------------------------------- taazz · 2018-08-10 09:38 Quote from: bobix on August 10, 2018, 11:27:42 amSo I am USING THREADS. Give me an example app with not freezing thread even if its form freezes. any thread that does not use synchronize for example the following thread will keep on running regardless of the state of the main thread. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i implementation {$R *.lfm}type  TUETestThread = class(TThread)  protected    procedure Execute; override;    procedure Complete(Data: PtrInt);  end; procedure TUETestThread.Complete(Data: PtrInt);begin  form1.Button2.Caption:='Threath: '+inttostr(Data);end; procedure TUETestThread.Execute;var  Thr : PtrInt = 0;begin while not Terminated do  begin    thr:=thr+1;    sleep(1);    Application.QueueAsyncCall(@Complete, Thr);  end;end; ---------------------------------------------------------------------- bobix · 2018-08-10 09:49 Thats what i was asking for! thank you!