Chapter 11. Creating Multithreaded Visual Basic .NET Applications

IN THIS CHAPTER

You were first introduced to Visual Basic .NET's multithreading capabilities in Chapter 3, “Major VB .NET Changes.” Chapter 3 had you create an application and place a procedure on a separate thread to keep you from blocking the execution in the calling procedure. This chapter starts with a similar example, and then proceeds to more advanced topics with the multithreading process.

In computer terms, a thread is something on which some execution occurs. On a single-processor system, the processor can actually execute only one thread at a time. However, multiple threads are executing all the time, and the CPU uses a scheduling mechanism to give each thread a time slice on the processor. In Visual Basic, all the functionality in an application ran on the same thread by default. If you called a procedure that ran for a long period of time, nothing else in the application ran until that procedure was finished. To have a long-running process yield to other input, VB had a DoEvents function that allowed the application to check for other input, such as mouse clicks or keystrokes. Although a new DoEvents method has been added to VB .NET, multithreading is one way that you can push processing off to other threads so that the rest of your application remains active.

DoEvents is not meant to run various pieces of code at the same time. Instead, it can just handle events that are raised, but it has to interrupt the processing of the current task in order to handle the event. The processing in the running task is halted while the event is handled. With multiple threads, you could have two pieces of code executing at the same time, each getting time slices on the CPU so that both continue operating.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.12.249