Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

.Invoke just calls the function normally and acts like it was called with just regular parentheses ().
.BeginInvoke starts a seperate thread that does nothing but run the function invoked.
.EndInvoke finishes up the previously invoked function and returns the proper return type.

Code Block
borderStylesolid
titleexample of .Invoke
borderStylesolid
def Nothing(x):
    return x

i = 5
assert 5 == Nothing(i)
assert i == Nothing.Invoke(i)
assert i == Nothing.Invoke.Invoke(i)

...

Here's a good example of .BeginInvoke

Code Block
borderStylesolid
titleMultithreading with .BeginInvoke
borderStylesolid
import System
import System.Threading

class FibonacciCalculator:
    def constructor():
        _alpha, _beta = 0, 1
        _stopped = true
    
    def Calculate():
        _stopped = false
        while not _stopped:
            Thread.Sleep(200)
            _alpha, _beta = _beta, _alpha + _beta
            print _beta
    
    def Start():
        _result = Calculate.BeginInvoke()
    
    def Stop():
        _stopped = true
        Calculate.EndInvoke(_result)

    _result as IAsyncResult
    
    _alpha as ulong
    _beta as ulong
    
    _stopped as bool

fib = FibonacciCalculator()
fib.Start()
prompt("Press enter to stop...\n")
fib.Stop()

...