B4J Question I am looking for the right waiting method without blocking?

T201016

Active Member
Licensed User
Longtime User
Hi,
I want to wait for the (Shell) to finish saving to the .mp4 file before I go to further instructions for creating another video file.
I do it this way:

B4J:
Do Until FileWatcher.IsReadable(FullPath)
    Sleep(100)
Loop
'Start to the next code line.

The above way seems to be good, but I noticed that sometimes it can turn on the line (to Until ... Loop)
Only half of them save per 100 files. What could be the cause? Too short set time for Filewatcher?
 

emexes

Expert
Licensed User
Longtime User
Three maybe fixes:

1/ after the loop, double-check that the file is still readable
2/ add a short sleep before and after 1/
3/ don't use the same filename each time (or maybe you're already not - I can't tell from the code you've given)

The technique of using a polling loop with a sleep inside it is one that Erel has used, so you're in good company.

 
Upvote 0

T201016

Active Member
Licensed User
Longtime User
Cześć @emexes, @walt61
Zakładając, że starałem się spowolnić działanie kilkuset startupów SHELL i zakończyć wyświetlanie okna z komunikatem dopiero po ostatnim uruchomieniu Shell. Udało mi się to zrobić TUTAJ:

Odpowiedź na pytanie @walt61: Używam shl.RunSynchronous(-1)
Dziękujemy za wsparcie 👍
 
Last edited:
Upvote 0

walt61

Well-Known Member
Licensed User
Longtime User
I tried to strive to slow down the operation of several hundred SHELL startups, and finish displaying the window with a message only after the last start of the Shell

If you use RunSynchronous, your code waits for the shell to complete, so you'd only be running one at a time, and can then show the completion message after your loop. No need for asynchronous shenanigans like Wait For in that case 🙂
 
Upvote 0

T201016

Active Member
Licensed User
Longtime User
Jeśli używasz RunSynchronous, Twój kod czeka na zakończenie powłoki, więc będziesz uruchamiać tylko jeden na raz, a następnie możesz wyświetlić komunikat o zakończeniu po pętli. W takim przypadku nie ma potrzeby stosowania asynchronicznych sztuczek, takich jak Wait For 🙂
Dobra sugestia, warto o tym pamiętać ;)
 
Upvote 0
Top