Thread is the smallest sequence of programmed instructions that can be managed independently , normally if we write coding and running that app , it will execute the code by sequential.
and what if we need process that running with main code on the same time but independently ?
so if main code parsing interupted by somehow code (example sleep) to stop execution temporary the another instance still running. USE THREAD.
How to
Concept :
1. Imports System.Threading
2. create var global thread3. create function / sub mythread(example)
4. create object thread and addressing to that function / sub mythread (example)
here's the code :
* create 1 button and double click
Imports System.Threading
Private objthread As Thread
Public Sub mythread()
' your routine here
End Sub
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdthread.Click
objthread = New Thread(AddressOf mythread)
objthread .IsBackground = True
objthread .Name = "NameThread"
objthread .Start() 'Start Thread
End Sub
Note : * after execution of function complete , thread automatically stop.
you can check them using method objthread.isAlive
* if you want keep the thread still alive , you can use infinite loop , but add sleep 1 - 3 second.
to use sleep use : System.Threading.Thread.Sleep(3000)
Post a Comment
Harap gunakan bahasa yang baik dan sopan, terima kasih