User Tools

Site Tools


Wait For Background Progress

Summary

Below are examples demonstrating how you can cause a script to wait for the background_progress indicator to finish before continuing.

API Areas of Interest

Example (Test)

Wait_Background_Progress_Test.dsa
// Define whether we are debugging
var bDebug = true;
 
// Define the total number of steps
var nSteps = 1000;
 
// If we're debugging
if( bDebug ){
	// Start a background progress
	startBackgroundProgress( "Background", nSteps, false );
}
 
// Initialize working variables
var bWasBusy = false;
var nCount = 0;
 
// While something is happening in the background
while( backgroundProgressIsActive() ) {
	// If we're debugging and we haven't captured that
	// the background is busy
	if( bDebug && !bWasBusy ){
		// Report that we've started to wait
		print( "Started Waiting:", (new Date).toTimeString() );
		// Capture that the background was busy
		bWasBusy = true;
	}
 
	// Allow the application to continue working
	processEvents();
 
	// If we're debugging
	if( bDebug ){
		// Increment our count
		nCount += 1;
 
		// Update the background progress to reflect our count
		updateBackgroundProgress( nCount );
 
		// If our count hasn't meet our total steps
		if( nCount < nSteps ){
			// Next!!
			continue;			
		}
 
		// Finish the background progress
		finishBackgroundProgress();
 
		// If we encountered being busy
		if( bWasBusy ){
			// Report that we've finished waiting
			print( "Finished Waiting:", (new Date).toTimeString() );
		}
	}
}

Example (Simple)

Wait_Background_Progress.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	// While something is happening in the background
	while( backgroundProgressIsActive() ) {
		// Allow the application to continue working
		processEvents();
	}
 
// Finalize the function and invoke
})();