Read From File Locking Up Whole Stack
Posted: Tue Jan 06, 2015 9:59 pm
So I've been tinkering with a way to copy files of various sizes without locking up the entire UI of LiveCode and so far I have gotten part way near to it with the idea to divide the file size up into chunks of 512, so we take the file size in bytes and divide it by the size of the chunk (i.e. 1024 / 512) and then I've got a Repeat loop that copies 512 bytes of the file using the Read From File command and then writes those 512 bytes to the destination file.
And this works well with smallish files (I'm not too sure of a limit, but I tried it out on a couple of Windows EXE files that are a couple hundred KB in size and it worked fine) but upon feeding it a just a lowly 16 meg DLL file it just face planted into the ground with the force of an asteroid. But the stack did copy the file, it took a while but it kept on running, just the UI locked up and after a couple of minutes the UI came back to life and the file was copied.
I used both the code sections below (The _CopyChunk message does the same Read From File and Write To File stuff as the first code section does) and both result in the UI locking up.
Original Code Used:
Revised Code:
So can anyone shed some light on ways I can do this whilst keeping the UI alive enough so that Windows does not state it is not responding. I know LiveCode does not have any multi-threading and thus this is basically an attempt to get around the single threaded nature of the engine. I seem to have been the only one begging for multi-threading to be apart of the new engine revamp, however I am unsure whether that has fallen on deaf ears.
TL;DR Read From File whitey's at anything more than a couple hundred kilobytes of data.
And this works well with smallish files (I'm not too sure of a limit, but I tried it out on a couple of Windows EXE files that are a couple hundred KB in size and it worked fine) but upon feeding it a just a lowly 16 meg DLL file it just face planted into the ground with the force of an asteroid. But the stack did copy the file, it took a while but it kept on running, just the UI locked up and after a couple of minutes the UI came back to life and the file was copied.
I used both the code sections below (The _CopyChunk message does the same Read From File and Write To File stuff as the first code section does) and both result in the UI locking up.
Original Code Used:
Code: Select all
If tChunkIndex < tNumberOfFileChunks Then
Read From File pSourceFilePath For 512 Bytes
Else Read From File pSourceFilePath Until EOF
Put It Into tFileChunk
Write tFileChunk To File pDestinationFilePath
If pMessage_ChunkCopied <> Empty Then
Dispatch pMessage_ChunkCopied To tTargetObject With tChunkIndex
End If
If tChunkIndex < tNumberOfFileChunks Then
Add 1 To tChunkIndex
Else Exit Repeat
Code: Select all
Put False Into tChunkCopyStatus
If tChunkIndex < tNumberOfFileChunks Then
Send ("_CopyChunk" && pSourceFilePath & Comma & pDestinationFilePath & Comma & False) To Me In 0 Seconds
Else Send ("_CopyChunk" && pSourceFilePath & Comma & pDestinationFilePath & Comma & True) To Me In 0 Seconds
Wait While tChunkCopyStatus = False With Messages
If pMessage_ChunkCopied <> Empty Then
Dispatch pMessage_ChunkCopied To tTargetObject With tChunkIndex
End If
If tChunkIndex < tNumberOfFileChunks Then
Add 1 To tChunkIndex
Else Exit Repeat
TL;DR Read From File whitey's at anything more than a couple hundred kilobytes of data.