User Tools

Site Tools


Background Progress

Summary

Below is an example demonstrating how you can cause the background_progress indicator to be displayed in the Status Bar and report progress via script.

API Areas of Interest

Example

Background_Progress.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	// Declare the total number of cycles
	var nCycles = 100000;
	// Declare how frequently you want to update the progress
	var nFrequency = 100;
 
	// Define whether or not the user can cancel
	var bCancellable = true;
 
	// Start the progress
	startBackgroundProgress( "This is a simple background progress test.", nCycles/nFrequency, bCancellable );
	// Iterate over the total number of cycles
	for( var i = 0; i < nCycles; i += 1 ){
		// If the iteration is divisible by the frequency, with no remainder
		if( i % nFrequency == 0 ){
			// Step the progress by 1
			stepBackgroundProgress( 1 );
 
			// Force any pending events to be processed
			// i.e. updating the status bar progress indicator
			processEvents();
		}
 
		// If the user is allowed to cancel
		if( bCancellable ){
			// Process events so that we can check user interaction
			processEvents();
 
			// If the user cancelled
			if( backgroundProgressIsCancelled() ){
				// We're done...
				break;
			}
		}
	}
 
	// Finish the progress
	finishBackgroundProgress();
 
// Finalize the function and invoke
})();