Problem: I call a sub that contains a File.copy(.....).
After calling the sub I load the file copied, but it seems that sometimes copy indicated into the sub isn't finished. I test with file.exists but then : what the most elegant solution ?
Example:
I try this...
After calling the sub I load the file copied, but it seems that sometimes copy indicated into the sub isn't finished. I test with file.exists but then : what the most elegant solution ?
Example:
B4X:
Sub One
....do something
callsub Two
Sleep ( ???? ) <-- 1000 ? 10000 ? 100000 ? It seems impossible to decide a correct value
If file.exists(File.dirinternal,"Odissea.txt") then
.........
else
log("File not copied")
????????
end if
end sub
Sub Two
.......do something
file.copy(file.dirassets,"Book.txt",file.dirinternal."Odissea.txt")
end sub
I try this...
B4X:
Sub One
....do something
callsub Two
Wait for Timer1_Tick
Timer1.enabled = false
.... do somethink
end sub
Sub Two
.......do something
file.copy(file.dirassets,"Book.txt",file.dirinternal,"Odissea.txt")
.......do something
do until file.exists(File.dirinternal,"Odissea.txt")
log("Copy not finished")
Sleep (500)
Loop
timer1.Inizialize("Timer1",1)
timer1.enabled = true
end sub
sub Timer1_tick
timer1.enabled = false
End sub[/CODE
It works but my question is : Are there other best solution to continue code only when the async func of a sub is finished ?