Part 15 - Functions as Objects and Multithreading
Having Functions act as objects exposes three very useful methods:
function.Invoke(<arguments>) as <return type>function.BeginInvoke(<arguments>) as IAsyncResultfunction.EndInvoke(IAsyncResult) as <return type>
.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.
example of .Invoke
Since .Invoke is a function itself, it has its own .Invoke.
Here's a good example of .BeginInvoke
Multithreading with .BeginInvoke
The output produces the Fibonacci sequence roughly every 200 milliseconds (because that's what the delay is). This will produce an overflow after it gets up to 2^64.
The important thing is that it stops cleanly if you press Enter.
