Click here to Skip to main content
13,344,508 members (50,611 online)
Click here to Skip to main content
Add your own
alternative version

Stats

290.1K views
16.2K downloads
101 bookmarked
Posted 9 Aug 2006

Multithreading with VB.NET - A beginner's choice

, 9 Aug 2006
Rate this:
Please Sign up or sign in to vote.
Multithreading is a technique by which you can increase the efficiency of your program by 100%. Everybody wants to apply multi-threading in their own applications. But for beginners, it's a bit difficult to apply multi-threading properly. But it's quite easy with VB.NET.

Sample Image - mutithreading_for_beginer.gif

Introduction

Hi friends,

This is my first article on Code-Project on the topic Multithreading in VB.NET.

Multithreading is a technique, by which you can increase efficiency of your program by 100%. Every body wants to apply multi threading in their own application. But for beginner it's a bit difficult to apply multi threading properly. I had the same problem, when I was going to use it in my application. That's why I am writing this article, that beginner can easily apply multi threading in their application. I am trying to make it as simple as possible.

I am not writing this article against some ones request. Rather than, I am writing this article, as I personally faced a big problem on this topic. It was so hard to find out a good solution or help on "How to apply threading on application".

After so much study, search on google and on other forums at last I was able to apply multi threading in my application.

Multi Threading is not a critical or complex thing to do. But many people don't now how to apply it. They can get sample code, but can't implement it on their own project. Or they face trouble, when they try to apply the code in their application.

I am not writing much code here. Because, if you download the source code, provided with this article, you will find comment through out each line of coding. So I am not repeating them again here

The heart of this project is the following line of coding

'The main mother class in .NET Framework to work with threading. 

Imports System.Threading  

'Creating Thread 
Dim objThreadClass As New clsThread(2, Me)
Dim objNewThread As New Thread(AddressOf objThreadClass.StartThread)
objNewThread.IsBackground = True
objNewThread.Start()
m_ThreadList.Item(1) = objNewThread 

'Receiving Message from thread
Public Sub ReceiveThreadMessage(ByVal ThreadIndex As Integer, _
                                ByVal Counter As Integer) 
    'do your work here depending on the return variables from the thread. 
End Sub 


'Sending Message from thread to the main application.
'First create a delegate (For details plz see the comments inside the codes) 

Private Delegate Sub NotifyMainWindow(ByVal ThreadIndex As Integer, _
                                      ByVal Counter As Integer)
'We need an object of this deletegate
Private m_NotifyMainWindow As NotifyMainWindow  

'Assign the pointer to the method of the main window to the delegate
m_NotifyMainWindow = AddressOf MainWindow.ReceiveThreadMessage 

'Create Argument List

ReDim m_Args(1)
m_Args(0) = m_ThreadIndex
m_Args(1) = m_Counter

'Call the notificaiton method on the main window by the delegate
m_MainWindow.Invoke(m_NotifyMainWindow, m_Args)

If this helps you, I'll be so happy

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Rakesh Mehta
Web Developer
India India
Hi,
This is Rakesh Mehta from India.
I am very very fond of programming (in any field).
I like to work on new technologies. Sometime, I face troubles, while looking for a new thing.
I am working as a Project Manager in Silicon Valley Infomedia Pvt Ltd. (India).
I'ld like to share all my new findings and solutions of problems with code project.

You may also be interested in...

Comments and Discussions

 
GeneralRe: How to make multithreading library? Pin
Bondan Wisnuwardhana2-Jul-08 21:16
memberBondan Wisnuwardhana2-Jul-08 21:16 
Generalbugs in If Not m_ThreadList(1) Is Nothing Then If CType(m_ThreadList(1), Thread).IsAlive Then Pin
raysky8-Jun-08 17:52
memberraysky8-Jun-08 17:52 
QuestionGOTO? Pin
Metaphore7-Oct-07 20:55
memberMetaphore7-Oct-07 20:55 
GeneralMultithreading in web services Pin
usha gupta7-Aug-07 21:50
memberusha gupta7-Aug-07 21:50 
GeneralRe: Multithreading in web services Pin
sikunj patel7-Jan-09 1:31
membersikunj patel7-Jan-09 1:31 
QuestionHow to use a main thread to start 4 sub threads Pin
Ramsky30-May-07 12:56
memberRamsky30-May-07 12:56 
AnswerRe: How to use a main thread to start 4 sub threads Pin
Skylinc10-Nov-09 0:37
memberSkylinc10-Nov-09 0:37 
QuestionA request from "Mr. Raj" Pin
Sean Ewington2-Apr-07 10:06
staffSean Ewington2-Apr-07 10:06 
Hello, i am a regular visitor of code project and i am new in multithreading application hear it's a nice application but it was created in a newer version of .net and we are using framework 1.1.4322 so i am not able to opena an applicaion so would you help like can you send it the related version code of multithreading thanks in advance.
Regards, Rajesh Champaneria
QuestionWhen do you use threading? Pin
gideon etan6-Mar-07 9:37
membergideon etan6-Mar-07 9:37 
Generalproblem in Multi threading Pin
nmehta00526-Feb-07 4:10
membernmehta00526-Feb-07 4:10 
GeneralRe: problem in Multi threading Pin
Rakesh Mehta26-Feb-07 6:19
memberRakesh Mehta26-Feb-07 6:19 
GeneralRe: problem in Multi threading Pin
harimv200226-Sep-12 22:33
memberharimv200226-Sep-12 22:33 
Generalthanks Pin
wmhp111-Jan-07 13:44
memberwmhp111-Jan-07 13:44 
GeneralThread Index Question Pin
eatwork9-Nov-06 13:14
membereatwork9-Nov-06 13:14 
GeneralRe: Thread Index Question Pin
eatwork9-Nov-06 13:22
membereatwork9-Nov-06 13:22 
GeneralRe: Counter variable problem Pin
Rakesh Mehta10-Nov-06 2:17
memberRakesh Mehta10-Nov-06 2:17 
GeneralRe: Counter variable problem Pin
eatwork14-Nov-06 11:40
membereatwork14-Nov-06 11:40 
GeneralRe: Counter variable problem Pin
eatwork14-Nov-06 12:21
membereatwork14-Nov-06 12:21 
GeneralRe: Thread Index Question Pin
Rakesh Mehta10-Nov-06 2:13
memberRakesh Mehta10-Nov-06 2:13 
GeneralSimple and to the point...thanks. [modified] Pin
Super Coder!26-Oct-06 3:50
memberSuper Coder!26-Oct-06 3:50 
GeneralGreat Work Pin
sscottatciqgroup16-Oct-06 11:59
membersscottatciqgroup16-Oct-06 11:59 
GeneralThank you very much Pin
guy_shlomo14-Sep-06 23:56
memberguy_shlomo14-Sep-06 23:56 
General:-) Pin
Yep-ItsMe18-Aug-06 15:44
memberYep-ItsMe18-Aug-06 15:44 
Generalagree Pin
iwdu15015-Aug-06 11:48
memberiwdu15015-Aug-06 11:48 
GeneralThe GoTo's have got ToGo! Pin
Matt J15-Aug-06 5:09
memberMatt J15-Aug-06 5:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 9 Aug 2006
Article Copyright 2006 by Rakesh Mehta
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid