如何通过将字符串传递给VB.NET中的后台线程来动态调用带有委托的函数?

时间:2009-05-20 03:36:55

标签: vb.net

如何通过在VB.NET中将字符串传递给后台线程来动态调用带有委托的函数?

目前我的代码是

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

最终会举起一个活动给我结果。

1 个答案:

答案 0 :(得分:0)

这就是我的所作所为:

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