When you deploy a PowerBuilder application that contains shared objects to .NET, the application can be run in a multithreaded environment. The PowerBuilder .NET runtime library also supports .NET synchronization, enabling your application to avoid possible data corruption.
This PowerScript code fragment uses .NET threading:
//Declare a .NET Class System.Threading.Thread ithread //Declare a delegate for .NET Thread System.Threading.ThreadStart threadproc //Assign a user defined PowerScript //function to the delegate threadproc = f_compute FOR Count = 1 TO a_count ithread = create System.Threading.Thread(threadproc) ithread.IsBackground = true ithread.Start() ithread.sleep(500) NEXT
When using threading in PB .NET, consider using .NET synchronization functions to protect user data from corruption. Synchronization functions require passing a System.Object instance to the functions, so your script must define a System.Object variable To use .NET synchronization functions in PowerScript:
For example:
//Declare a System.Object class System.Object obj //PowerScript function definition //using .NET thread synchronization //functions global subroutine f_compute (); System.Threading.Monitor.Enter(obj); gCount = gCount + 1 System.Threading.Monitor.Exit(obj); end subroutine
For printing DataWindow and DataStore objects, these limitations apply:
//ids is a datastore instance ids.object.DataWindow.Print.FileName =ls_filename ids.Print( False, False)
dwThread = create Thread (dwMethodFunc) dwThread.SetApartmentState(ApartmentState.STA!) dwThread.Start()