Using Multithreading
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.
.NET Threading in PowerScript
This PowerScript code fragment uses .NET threading:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#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 |
Using .NET Synchronization Functions
To use .NET synchronization functions directly in PowerScript:
- Declare a global variable.
- Initialize the global variable.
- Use the global variable in your .NET synchronization functions. Define your types
and functions within #IF DEFINED and #END IF preprocessor statements.
Windows Form example:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/* 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 |
Parent topic: Support for .NET language features
Document get from Powerbuilder help
Thank you for watching.
Subscribe
Login
0 Comments
Oldest