K
Kerry Jenkins
I am having problems passing an Event Delegate as an argument to a
method that accepts a delegate argument. I get the following error
message:
'Public Event ProgressChanged(sender As Object, e As
System.EventArgs)' is an event, and cannot be called directly. Use a
'RaiseEvent' statement to raise an event.
I don't want to raise the event, but rather pass the delegate
associated with an event to another method.
Here is some sample code to demonstrate the problem:
Imports System.ComponentModel
Public Delegate Sub ProgressChangedEventHandler(ByVal sender As
Object, ByVal e As EventArgs)
Public Class BackgroundWorker
Inherits Component
Public Event ProgressChanged As ProgressChangedEventHandler
Protected Overridable Sub OnProgressChanged(ByVal progressArgs As
EventArgs)
'**** Error occurs on the following line ******
ProcessDelegate(ProgressChanged, Me, progressArgs)
End Sub
Sub ProcessDelegate(ByVal del As [Delegate], ByVal args() As
Object)
Dim temp As [Delegate] = del
If (temp Is Nothing) Then
Exit Sub
End If
Dim delegates() As [Delegate] = temp.GetInvocationList()
Dim handler As [Delegate]
For Each handler In delegates
InvokeDelegate(handler, args)
Next
End Sub
End Class
I am attempting to convert Juval Lowy's .net 1.1 BackgroundWorker
component from C# to VB. I cannot get past the error above.
Article discussing this component:
http://www.code-magazine.com/Article.aspx?quickid=0403071
Link to the C# code:
http://www.idesign.net/idesign/uploads/Background with 1.1.zip
Thank you,
Kerry Jenkins
method that accepts a delegate argument. I get the following error
message:
'Public Event ProgressChanged(sender As Object, e As
System.EventArgs)' is an event, and cannot be called directly. Use a
'RaiseEvent' statement to raise an event.
I don't want to raise the event, but rather pass the delegate
associated with an event to another method.
Here is some sample code to demonstrate the problem:
Imports System.ComponentModel
Public Delegate Sub ProgressChangedEventHandler(ByVal sender As
Object, ByVal e As EventArgs)
Public Class BackgroundWorker
Inherits Component
Public Event ProgressChanged As ProgressChangedEventHandler
Protected Overridable Sub OnProgressChanged(ByVal progressArgs As
EventArgs)
'**** Error occurs on the following line ******
ProcessDelegate(ProgressChanged, Me, progressArgs)
End Sub
Sub ProcessDelegate(ByVal del As [Delegate], ByVal args() As
Object)
Dim temp As [Delegate] = del
If (temp Is Nothing) Then
Exit Sub
End If
Dim delegates() As [Delegate] = temp.GetInvocationList()
Dim handler As [Delegate]
For Each handler In delegates
InvokeDelegate(handler, args)
Next
End Sub
End Class
I am attempting to convert Juval Lowy's .net 1.1 BackgroundWorker
component from C# to VB. I cannot get past the error above.
Article discussing this component:
http://www.code-magazine.com/Article.aspx?quickid=0403071
Link to the C# code:
http://www.idesign.net/idesign/uploads/Background with 1.1.zip
Thank you,
Kerry Jenkins