Implementing Multiple Threads using VB.Net 2.0
Author: Zunnair
This Article helps you to understand the use multiple threads to achieve concurrency in tasks. This Article does not include synchronization, because no data is being accessed by multiple threads.
This Article does not include synchronization, as it is not needed for this code. However, when using multiple threads and sharing data, synchronization is critical.
Because multi-threaded code presents complexities when stepping through it, the Debugger Step Through attribute is applied at the multithreaded points. Attempting to step through the multi-threaded sections may yield inconsistent results. This example only writes to each window from the thread that is managing it. When writing to a window from threads other than the thread managing that window, additional attention is required. An asynchronous delegate is an easy way to run a task on a worker thread, but is not the only way to do so.
Source Code is Given For Your Bettter Understanding.
To run the task on a worker pool thread, you can use an asynchronous invocation on a delegate. For this example, we'll declare a delegate named TaskDelegate, and call it asynchronously. The signature of the delegate declaration must match the method (TheLongRunningTask)exactly.
To run the task an a thread from the worker pool, create an instance of a delegate whose signature matches the method that will be called, then call BeginInvoke on that delegate. For this example, the arguments and return value of BeginInvoke are unneeded. This technique is sometimes referred to as "Fire and Forget".
To run the task on a newly created OS thread (rather than a tread from the thread pool), create a new instance of a managed thread. The constructor takes the address of a subroutine with no arguments.