Forum > Other

unblocked Sleep() for all Platforms

<< < (2/4) > >>

KodeZwerg:

--- Quote from: Red_prig on August 27, 2022, 04:19:16 pm ---In principle you can use https://wiki.lazarus.freepascal.org/TTimer maybe this will work for you

--- End quote ---
I do know about TTimer but that will not stop my workflow.

just exemplary...

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  DoJob(); // start a method  Sleep(5000); // wait 5 seconds on this line of code without that app will be frozen  DoAnotherJob(); // start another method I hope that was more clear.

MarkMLl:

--- Quote from: KodeZwerg on August 27, 2022, 04:16:03 pm ---That is blocking. I do need unblocked version. (Application shall not freeze)

--- End quote ---

Put the background computation in a separate thread.

MarkMLl

Red_prig:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---DoJob(); // start a method Timer1:=TTimer.Create;Timer1.Interval := 5000;Timer1.Enabled := True;Timer1.OnTimer := OnTimerCb;Exit; //......... procedure TForm1.OnTimerCb(Sender: TObject);begin Timer1.Enabled := False; DoAnotherJob(); // start another methodend;  

KodeZwerg:
Ok, i still was not precise enough.

I do have a lot of sources/projects where i call my variant of Sleep() like the RTL is doing just without blocking.
I can not outsource following code into tthreads or create ttimers all over.

So what i actual mean is, i am a lazy guy that just likes to exchange my version with a CrossCompile version :)
I am really not looking for work-arounds.

Thank you for reading and your patience with me!

Josh:
not sure how cross platform, or how low cpu would be, not that accurate.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure WaitForInterval(msecs:Longint);var  currenttime,targettime,timetodelay:cardinal;  sleep_delay:integer=40; //delay before application.ProcessMessages calledbegin  currenttime:=DateTimeToTimeStamp(now).Time;  timetodelay:=currenttime;  targettime:=currenttime+msecs;  while currenttime<targettime do  begin    currenttime:=DateTimeToTimeStamp(now).Time;    if currenttime-timetodelay>Sleep_delay then    begin      application.ProcessMessages;  // keep alive      timetodelay:=currenttime;    end    else sleep(sleep_delay div 2); // go to sleep for 1/2 of sleep delay  end;end;    

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version