473,473 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Passing Event Delegate as an argument

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...uickid=0403071

Link to the C# code:
http://www.idesign.net/idesign/uploa...with%201.1.zip

Thank you,
Kerry Jenkins
Nov 20 '05 #1
1 6407
Kerry,
'**** Error occurs on the following line ******
ProcessDelegate(ProgressChanged, Me, progressArgs) As the message states, you are attempting to pass the Event itself to
ProcessDelegate. You need to pass the hidden Delegate field that VB.NET
creates for you.

Try something like:
'**** Error occurs on the following line ******
ProcessDelegate(ProgressChangedEvent, Me, progressArgs)
Hope this helps
Jay

"Kerry Jenkins" <ke***********@hotmail.com> wrote in message
news:82**************************@posting.google.c om... 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...uickid=0403071

Link to the C# code:
http://www.idesign.net/idesign/uploa...with%201.1.zip

Thank you,
Kerry Jenkins

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Pohihihi | last post by:
This might sound little stupid to many but I was thinking that when we can use object why we really need event args to pass in any functions e.g. bool MyFunction(object sender, System.EventArgs...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
6
by: Max | last post by:
Last time I tried to explain this on another forum it didn't go too well, so I'll try my best and if you know what I'm talking about then please tell me how to do this. I have a class, inside I...
5
by: Just Me | last post by:
I have these three statements: gFormCheckForCancel = New FormCheckForCancel AddHandler gFormCheckForCancel.Cancelled, AddressOf UserCancelled gFormCheckForCancel.ShowForm()
2
by: darthghandi | last post by:
I am trying to pass a socket object when an event is signaled. I have successfully bound to a network interface and listened on a port for incoming connection. I have also been able to accept...
4
by: Claire | last post by:
Visual Studio 2003 I have a thread running a small timeout. Rather than defining my own delegate I decided to be lazy and use a standard EventHandler delegate When OnReadMessageTimeout is...
4
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
2
by: Israel | last post by:
It seems like there should be a way to pass events around like delegates but on the other hand they’re sort of special delegates because the only one allowed to invoke them is the owner of the...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.