Monday 13 August 2012

Multithreading in vb.net

In this tutorial, we cover the concept of Multithreading. Multi Threading allows an application to run different bits of code at the same time without causing your User Interface to become unresponsive. This tutorial will hopefully explain the concept of multithreading to you and use of multithreading in advanced run one application more than one time and saving your time. Example if you want enter student data base at a time for different student data we can’t enter that’s why we come across multithreading, Make multithreading application 2 labels 2 buttons Explain Line:
1) Declare two variables and name it as (i) and (i2)
2) Declare two Threading variables as thread1 and thread2
3) Create two sub countup(),countup2()
4) And start thread by New System.Threading.Thread(AddressOf countup)
5) And start 2nd thread by New System.Threading.Thread(AddressOf countup)
6) Start threads Copy and paste below Code:
Public Class Form1
Dim i As Integer
Dim i2 As Integer
Dim thread As System.Threading.Thread
Dim thread2 As System.Threading.Thread
Private Sub countup()
Do Until i = 10000
i = i + 1
Label1.Text = i
Me.Refresh()
Loop
End Sub
Private Sub countup2()
Do Until i2 = 10000
i2 = i2 + 1
Label2.Text = i2
Me.Refresh()
Loop
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
thread = New System.Threading.Thread(AddressOf countup)
thread.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
thread2 = New System.Threading.Thread(AddressOf countup2)
thread2.Start()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CheckForIllegalCrossThreadCalls = False
End Sub
End Class