Passing events to another class

G

Guest

Is there any way to pass an array of events to another class? My idea is to
pass an array of events that will be fired by a managed object whenever a
manager class should update itself. The manager class would get the array of
events from a managed object when the managed object is associated with the
manager (in order to add event handlers) and then again when the managed
object is disassociated with the manager (in order to remove the event
handlers).

Thanks for any help.
Lance
 
P

Peter Huang [MSFT]

Hi Lance,

I think a event is kind of delegate which is also known as callback
machensim.
The class(B) out of the classobject (A), add event handler of A, that is
similar with store a function pointer in the A's callback collection.
When the B call some method of A, the A's method will call the function
pointer that B assigned to it before.

So I think the manager class just needed to pass the classobject(A)'s
reference and then call the fireevent's method in A.

[pseudocode]
class classobject
{
event TestEvent
void FireTestEvent()
{
raiseevent TestEvent
}
}

class managedclass
{
void FireObjectEvent(object o)
{
o.FireTestEvent
}
}

If I have any misunderstanding, can you please describe your scenario more
detailed.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top