We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

40- MultiThreading

Multithreading (or free threading) can execute multiple tasks simultaneously  in the Visual Basic applications. This is a process of individual tasks that execute on separate threads. Multithreading enhances the performance and responsiveness of your applications.



  • Open the Visual Basic, select “File” on the menu, hit new and create a new project.
  • The New Project dialog will appear.
    Select “windows” in the project types, hit the “windows form application” in the templates and hit “ok“.
  • Add two buttons and two textboxes in the form.
  • Add the following code in the code editor.
  1. Dim i As Integer
  2. Dim i2 As Integer
  4. Dim Mthread As System.Threading.Thread
  5. Dim Mthread2 As System.Threading.Thread
  7. Private Sub incValue()
  8. Do Until i = 100
  9. i = i + 1
  10. TextBox1.Text = i
  11. Me.Refresh()
  12. Loop
  13. End Sub
  15. Private Sub incValue2()
  16. Do Until i2 = 100
  17. i2 = i2 + 1
  18. TextBox2.Text = i2
  19. Me.Refresh()
  20. Loop
  21. End Sub
  23. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  24. Mthread = New System.Threading.Thread(AddressOf incValue)
  25. Mthread.Start()
  26. End Sub
  28. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  29. Mthread2 = New System.Threading.Thread(AddressOf incValue2)
  30. Mthread2.Start()
  31. End Sub
  33. Private Sub multithread_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  34. Control.CheckForIllegalCrossThreadCalls = False
  35. End Sub


Facebook Comments
(Visited 4 times, 1 visits today)
Share this

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked * © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!

%d bloggers like this: