Posted by: Sourav | October 1, 2016

Retrieve data from thread using delegate,VB Teacher Sourav,Kolkata 09748184075

Imports System.Threading
Public Delegate Sub sumofnumbersdelegate(ByVal sumofnumbers As Integer)
Module Module1
Sub sumofnumbers(ByVal result As Integer)
Console.WriteLine(“The result is {0}”, result)

End Sub

Sub Main()
Console.WriteLine(“Please enter the target number”)
Dim target As Integer = Convert.ToInt32(Console.ReadLine)
Dim sumofnumbersdelegate1 As sumofnumbersdelegate = New sumofnumbersdelegate(AddressOf sumofnumbers)
Dim number As numbers = New numbers(target, sumofnumbersdelegate1)

Dim t1 As Thread = New Thread(AddressOf number.sumofnumbers)


End Sub

End Module

Public Class numbers

Private target As Integer
Private sumofnumbersdelegate As sumofnumbersdelegate
Public Sub New(ByVal target As Integer, ByVal sumofnumbersdelegate As sumofnumbersdelegate) = target
Me.sumofnumbersdelegate = sumofnumbersdelegate

End Sub

Public Sub sumofnumbers()
Dim result As Integer = 0

Dim i As Integer
For i = 1 To target
result = result + i
If Not IsNothing(sumofnumbersdelegate) Then
End If
End Sub

End Class


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: