Example of StatusbarProgress Update

Just starting out? Need help? Post your questions and find answers here.
tester
User
User
Posts: 34
Joined: Sun Dec 28, 2014 1:12 pm

Re: Example of StatusbarProgress Update

Post 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     
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: Example of StatusbarProgress Update

Post 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.
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Example of StatusbarProgress Update

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Example of StatusbarProgress Update

Post 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. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply