Multithreading in VB.NET

Introduction

Multithreading, a very powerful technique, is essential for modern software development.  Software users expect to work with a very responsive program that they don’t have to wait on, which is a very reasonable demand with the processor speeds that are currently available.  Enter multithreading.  Multithreading is the concept of having several different paths of code running at the same time.

When you introduce multithreading in your applications, you immediately make programming more complicated and add design time.  You must know exactly what your application and all its threads are doing at all times.  You have to account for deadlocks, race conditions and corrupting variable values.  In this article we will examine the different methods in Visual Basic.Net to accomplish thread synchronization.  We will learn what deadlocks and race conditions are and how to avoid these common problems with multithreading.

System Requirements

I will assume that you already have knowledge of basic threading in Visual Basic.Net.  You should know how to create threads and know how to do basic threading operations like Join and Sleep.  A copy of Visual Studio.Net is required to run the code samples and see the output. The code was written with Visual Studio.Net using version 1.0 of the .Net Framework with service pack 2.

Case Study Structure

This case study has three main parts.  Multithreading requires a technique called synchronization to eliminate the problems described above so we will first take a brief look at what synchronization is.  Then an in-depth look at all methods available in Visual Basic.Net for synchronization will be presented where you will learn how to correctly synchronize a multithreaded application.  After this, a look at Window’s Form synchronization and threading apartment styles will show the differences a programmer must handle between standard synchronization and visual GUI synchronization.

You might also like...

Comments

About the author

John Spano United States

John Spano cofounder and CTO of NeoTekSystems, a Greenville, South Carolina technology consulting company. NeoTekSystems offers IT consulting, custom programming, web design and web hosting. We ...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Linux is only free if your time has no value” - Jamie Zawinski