#============================================================================== # # Project: SharpImage # Module: ThreadedScript.py # Language: IronPython # Author: Dan Mueller # Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $ # Revision: $Revision: 2 $ # # Copyright (c) Queensland University of Technology (QUT) 2007. # All rights reserved. # # This software is distributed WITHOUT ANY WARRANTY; without even # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the above copyright notices for more information. # #============================================================================== # Import the base script class import Script from Script import * # Import symbols from desired assemblies from System.Threading import * class ThreadedScriptObject(ScriptObject): Name = "ThreadedScript" Thread = None def Run(self): """ The entry-point for this script. """ try: self.Initialise() if ( self.Success ): self.DoWork() except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) ScriptObject.Finalise( self ) def DoWork(self): """ Perform the main functions of the script. """ """ NOTE: This function is invoked on the main UI thread. """ self.Thread = Thread( ThreadStart(self.ThreadedDoWork) ) self.Thread.Name = self.Name + "Thread" self.Thread.Start() def ThreadedDoWork(self): """ Perform the main functions of the script. """ """ NOTE: This function is invoked on a background thread. """ # Subclasses must override def FinishedWork(self, success): """ Inform listeners that the work has finished. """ ScriptObject.FinishedWork( self, success ) if ( success ): self.ParentApplication.Invoke( CallTarget0(self.Finalise) )