I'm using vb.net in visual basic 2008. I'm wondering how perfom sequential tasks using vb.net ??
Example :
Do Task 1 then Move to Task 2 when Task 1 is complete
Any idea Please ? Which things and tools I have to use to solve this problem ?
I'm using vb.net in visual basic 2008. I'm wondering how perfom sequential tasks using vb.net ??
Example :
Do Task 1 then Move to Task 2 when Task 1 is complete
Any idea Please ? Which things and tools I have to use to solve this problem ?
.NET framework has a Task
class, which supports Task continuation
. You would use Task.ContinueWith to chain them together. Here is a code sample:
Imports System.Threading.Tasks
Public Class Form1
Dim _var1 As Integer = 0
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim task1 As task = Task.Factory.StartNew(AddressOf Task1_Code).ContinueWith(AddressOf Task2_Code)
task1.Wait()
MessageBox.Show(_var1)
End Sub
Sub Task1_Code()
Threading.Thread.Sleep(1000)
_var1 = 5
End Sub
Sub Task2_Code()
Threading.Thread.Sleep(1000)
_var1 *= 5
End Sub
End Class