Library tutorials & articles
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.
Related articles
Related discussion
-
Multithreading Modal Form/Message
by Akhtar Hussain (0 replies)
-
bar graphs in visual basic.net
by bhabybash (1 replies)
-
How to write the category attribut in a class dynamically
by converter2009 (1 replies)
-
VB.NET: Hide and show table using radio buttons
by converter2009 (1 replies)
-
VB.Net Button Problem
by pysdex (0 replies)
Related podcasts
-
Concurrency Pt. 2
Podcast (MP3): Download Hosts: Alexander Michael Guests: Recording venue: In this second part of our concurrency series Michael and Alexander talk about basic patterns for concurrent programming, such as Active and Monitor Object, Scoped Locking and ...
I need to lock the Log file once someone is using it and second person shouldn't able to write in log file. The code is shown below :
Imports System Imports System.IO
Module FileTransfer
End Module
!--removed tag-->Bundle of thanks to the author, it is very help full
As somewhat of an advanced "newbie" I have read many articles on Multithreading, and am at a loss
Do I need to have a delegate and call the delegate when I am using threading ?
Lets say I have a datatable with 5 million rows and I need to iterate through each row - grab some info , process that info (translate it) and then save it somewhere else. For example insert it inot a completely different database (and maybe even RDBMS - Architectur)
Now I currently for each row - but that takes a lot of time.
I would like to spawn a (Flexible Number of threads) to do the row processing - Will my For each move on as each thread runs. So I start Thread(1) will the next trigger, and I have a new row and can start thread(2) and so on. Also my Subroutine, must
Yes, but I decided not to go into detail since it's a vb.net article and you can't use it
Volatility means a lot more than is described in the article. It doesn't just affect the variable which has the volatile modifed; it affects the whole memory model for sections of code involving access to that variable.
I agree that there's no use of volatile which can't be semantically achieved using locks, and indeed I generally prefer to use locks myself. However, there is a speed difference between acquiring a lock and just using a volatile variable - in a very few cases it might be significant. I'm surprised VB.NET doesn't have any way of specifying this.
See the volatility page of my C# threading article for more information.
Jon Skeet
This thread is for discussions of Multithreading in VB.NET.