If clients don't subscribe to events

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a class which exposes number of events. If client doesn't subscibe to
an event, I get a runtime error when event is raised. What's the way to deal
with it?, other than making sure all events are subscribed to.
 
Lenn said:
I have a class which exposes number of events. If client doesn't subscibe
to
an event, I get a runtime error when event is raised. What's the way to
deal
with it?, other than making sure all events are subscribed to.

if (this.EventHandler != null) {
// raise event
}

hth :)

Mythran
 
Mythran said:
Hmm, really? That is Microsoft's recommended approach, but I do see how it
would not be thread safe w/o some sort of lock...

Microsoft unfortunately often forgets thread-safety when it puts
together code patterns...

(Of course, it's not a problem in the situation where you don't need
your type to be thread-safe. Most types probably *shouldn't* be thread-
safe, IME.)
 
Actually I am dealing with multithreaded application. But it's really 2
threads, UI and worker thread, only 1 thread at a time will own that code
section ,so I don't think thread-safety is something to worry about. Or
should I?
 

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

Back
Top