Page 2 of 2
Re: Example of StatusbarProgress Update
Posted: Wed Mar 11, 2020 11:10 pm
by tester
TI-994A wrote:...
Code: Select all
; read #copyChunkSize data into memory buffer
ReadData(#sourceFile, *fileCopyBuffer, #copyChunkSize)
; write #copyChunkSize data into destination file
WriteData(#destinationFile, *fileCopyBuffer, #copyChunkSize)
; decrease remaining data to be written
destinationFileLen - #copyChunkSize
To work correctly, you need to slightly modify the code:
Code: Select all
; read #copyChunkSize data into memory buffer
nBytesRead=ReadData(#sourceFile, *fileCopyBuffer, #copyChunkSize)
; write nBytesRead data into destination file
WriteData(#destinationFile, *fileCopyBuffer, nBytesRead)
; decrease remaining data to be written
destinationFileLen - nBytesRead
Re: Example of StatusbarProgress Update
Posted: Thu Mar 12, 2020 12:56 am
by Columbo
Thank you netmaestro. Clear explanation. Until I received the code examples from yourself and TI-994A I was unaware that there was such a procedure.
Thanks again and thanks also to Sicro for the link.
Cheers.
Re: Example of StatusbarProgress Update
Posted: Thu Mar 12, 2020 3:43 am
by TI-994A
Columbo wrote:Thank you netmaestro. Clear explanation...
Yes;
perfectly articulated!
In technical terms, threads facilitate asynchronous execution, while standard procedures would run synchronously within the main thread. This can be clearly demonstrated by simply replacing the thread creation with a standard call to the procedure.
In the example above, somewhere around line 125, in the
StartFileCopy() procedure, make the following edits:
Code: Select all
;copyThread = CreateThread(@FileCopyProgress(), 0)
FileCopyProgress(0)
The procedure will run synchronously and block all other execution until it completes, so it might be best to try it out with a small file.
Re: Example of StatusbarProgress Update
Posted: Thu Mar 12, 2020 4:00 am
by TI-994A
tester wrote:To work correctly, you need to slightly modify the code:
Code: Select all
nBytesRead=ReadData(#sourceFile, *fileCopyBuffer, #copyChunkSize)
WriteData(#destinationFile, *fileCopyBuffer, nBytesRead)
This would fall into the purview of error-checking, which would entail far more than just bytes read. It has to account for bytes written as well, and the adjustment of the file pointer for subsequent reads.
Among other things.
Nevertheless, beyond the scope of a simple illustrative example.
