Event being receiced more than once!

G

Guest

BACKGROUND
I have the following classes as part of a program that opens 3 Asynchronous
Sockets. Each socket is in a separate instance of a wrapping class.

1x User Interface class
1x Client Manager class
3x Client class Instances

The Client class raises events when the client connects.
The User interface has registered with that event.

PROBLEM
The UserInterface event handler is called between 1 and 3 times
The event is definately only firing once and the ui has definately only
registered for the event once so the question is - Why is the event handler
being called more than once!!!!????

Thanks,
Shaun
 
S

Stoitcho Goutsev \(100\)

Is that an event that you have declared and implemented?

I pretty sure the event has been hooked on more that once. If you have
declared the event try to change the declaration using add and remove
accessors. Then put a break point in the add accessor to see how many times
the event is hooked.
 
G

Guest

The event is one that i have declared myself.
I gave it a subscribe function to handle anything that wanted to receive
notification of the event. The Subscribe event is only called once by the
client manager for each instance of the client class that it creates. (3
instances).

Interestingly, if the Clientmanager class instantiates X instances of the
client class then whenever the event is fired by any of the instantiated
classes, the ClientManager event handler is called X times.!
 
S

Stoitcho Goutsev \(100\)

Is it by any chance event declared as static? What you just described will
happen in this case.
 
J

Jon Skeet [C# MVP]

ShaunO said:
BACKGROUND
I have the following classes as part of a program that opens 3 Asynchronous
Sockets. Each socket is in a separate instance of a wrapping class.

1x User Interface class
1x Client Manager class
3x Client class Instances

The Client class raises events when the client connects.
The User interface has registered with that event.

PROBLEM
The UserInterface event handler is called between 1 and 3 times
The event is definately only firing once and the ui has definately only
registered for the event once so the question is - Why is the event handler
being called more than once!!!!????

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 

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