How to call a function dynamically with delegates passing a string to a background thread in VB.NET?

How to call a function dynamically with delegates passing a string to a background thread in VB.NET?

Currently my code is

Public Sub invertImageBK(ByVal image As Bitmap)
    Dim snxl As System.ComponentModel.BackgroundWorker = createBW()
    snxl.RunWorkerAsync(New ImageProperties(image.Clone, "invertImage", Nothing))
End Sub
Public Sub grayscaleImageBK(ByVal image As Bitmap)
    Dim snxl As System.ComponentModel.BackgroundWorker = createBW()
    snxl.RunWorkerAsync(New ImageProperties(image.Clone, "grayscaleImage", Nothing))
End Sub
Public Sub colorizeImageBK(ByVal image As Bitmap, ByVal colorize As Color)
    Dim snxl As System.ComponentModel.BackgroundWorker = createBW()
    snxl.RunWorkerAsync(New ImageProperties(image.Clone, "colorizeImage", colorize))
End Sub

Private Sub ConvertImage(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
    If e.Argument.extra IsNot Nothing Then
        Dim snxl As New twoarg()
    Else

    End If

End Sub

Private Delegate Function onearg(ByVal image As Bitmap) As Bitmap
Private Delegate Function twoarg(ByVal image As Bitmap, ByVal altcolor As Color) As Bitmap

Private Function createBW() As System.ComponentModel.BackgroundWorker
    Dim cbs As New System.ComponentModel.BackgroundWorker
    AddHandler cbs.DoWork, AddressOf ConvertImage
    Return cbs
End Function

Public Structure ImageProperties
    Dim img As Bitmap
    Dim filt As String

    Public Sub New(ByVal image As Bitmap, ByVal filter As String, ByVal extra As Object)
        img = image.Clone
        filt = filter
    End Sub
End Structure

      

and this will eventually raise an event to give me my result.

0


a source to share


1 answer


That's what I'm doing:



Private Function oneargImplementation(ByVal image As Bitmap) As Bitmap

End Function

Public Sub Test()

Private ArgOne as onearg = _
    new onearg(AddressOf oneargImplementation)
Dispatcher.Invoke(ArgOne, Windows.Threading.DispatcherPriority.Loaded, New Object() {sender, e})
End Sub

      

0


a source







All Articles