When you deploy a PowerBuilder application that contains shared objects or an NVO assembly 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:
#if defined PBDOTNET then //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 #else /*action*/ #end if
To use .NET synchronization functions directly in PowerScript:
Windows Form example:
/* declare and initialize global variable */
System.Object obj
obj = create System.Object
#if defined PBWINFORM then
System.Threading.Monitor.Enter(obj);
#else
/*action*/
#end if
b = 1000/globala
globala = 0
a = 1000
globala = 10
b = a / globala
#if defined PBWINFORM then
System.Threading.Monitor.Exit(obj);
#else
/*action*/
#end if
return 1