Code works with BREAK, but not without

I am fairly new to Xojo. I have a simple routine that copies a file to another location, and checks if the destination file already exists. The code does not work when I run it in the development environment, but it DOES work when I insert a BREAK. I have run it with and without the BREAK, and the code behaves differently. Here is the code:

[code]
IF DestinationFile.Exists THEN

SELECT CASE DialogBox (kGraphicCaution, “Desination File Already Exists”, “A file by the same name already exists in the destination folder”, “Do you want to OVERWRITE the existing file, create a NEW COPY, or CANCEL?”, “Overwrite”, “New Copy”, “Cancel”, 3)

CASE 1 ’ Overwrite

DestinationFile.Delete

BREAK

IF DestinationFile.LastErrorCode = 0 THEN
SourceFile.CopyFileTo(DestinationFolder)
IF SourceFile.LastErrorCode = 0 THEN
CALL NoteBox (“Copy Successful”, "I overwrote " + SourceFile.Name + " on " + DestinationFolder.Name)
ELSE
CALL StopBox (“Copy Failed”, “I successfully deleted the destination file " + DestinationFileName + " but I could not copy the source file to the destination file”, "Error Code " + STR(SourceFile.LastErrorCode))
EXIT SUB
END IF

ELSE
CALL StopBox (“Copy Failed”, "I could not overwrite the destination file " + DestinationFileName, "Error Code " + STR(DestinationFile.LastErrorCode))

END IF

CASE 2 ’ New Copy

CASE 3 ’ Cancel

END SELECT[/code]

I have created a condition where the destination file exists and is in use. The code should report “I could not overwrite the destination file”. When the BREAK is not in place, the code passes through the IF statements as if they are all true, and then reports “I overwrote …” even though it clearly did not. When I insert the BREAK where shown, I confirm DestinationFile.LastErrorCode = 102. When I resume from break IT WORKS PROPERLY (sometimes).

What am I doing wrong? Any help will be appreciated.

Platform ?

FWIW there are several channels - and there are ones for Windows, Linux, macOS, iOS etc
Posting in the one you’re specifically asking about helps

probably a timing issue… and the BREAK allowed everything to catch up

this is my thinking as well … and I expect this might bs macOS (possibly on mojave and an APFS filesystem)

A variation of <https://xojo.com/issue/49147> ? I recently ran into this §$%& problem myself - again.

very possibly
the frameworks use older file system api’s so any ide’s that used normal framework code to remove files could have issues
I know I swapped some code for new file system apis I just dont recall what version those are in

mostly this has to do with how Apple chnagedolder apis to access APFS volumes
they literally shove those alls off into an XPC service and so they seem to be synchronous but experience says they arent always and so you end up with conditions where the XPC call says the delete succeeeded but its actually still in progress
Xojo is far from alone in experiencing this