Delay() inside "While ProgramRunning..."-Loop?

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

Delay() inside "While ProgramRunning..."-Loop?

Post by Lebostein »

Should a delay be included here? I have the whole thing running in a thread....

Code: Select all

While ProgramRunning(programID)
  ; Delay() ???
  If AvailableProgramOutput(programID)
    output$ + ReadProgramString(programID) + #CRLF$
  EndIf
Wend
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Delay() inside "While ProgramRunning..."-Loop?

Post by STARGÅTE »

Yes, a Delay(0) is enough.

Code: Select all

While ProgramRunning(programID)
  If AvailableProgramOutput(programID)
    output$ + ReadProgramString(programID) + #CRLF$
  Else
    Delay(0)
  EndIf
Wend
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
jacdelad
Addict
Addict
Posts: 1992
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Delay() inside "While ProgramRunning..."-Loop?

Post by jacdelad »

Please ignore my ignorance, but what does a Delay(0) do?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Delay() inside "While ProgramRunning..."-Loop?

Post by NicTheQuick »

It instructs the scheduler of your operating system to use the CPU for an other thread/process until the scheduler decides to give your thread attention again.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Delay() inside "While ProgramRunning..."-Loop?

Post by Crusiatus Black »

NicTheQuick wrote: Fri Apr 01, 2022 7:44 pm It instructs the scheduler of your operating system to use the CPU for an other thread/process until the scheduler decides to give your thread attention again.
Is that not only true for Windows?
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
Post Reply