New to C# -- Events

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I need to raise events from a c# class to the caller, a c#
or vb form. In VB you would declare the event in the
class, then just use the RaiseEvent to raise the event, in
the form you would just create a handler that would handle
that event.

How do you do this same thing in c#? Is it possible to
raise events from a C# class to either a C# windows
application or a VB windows application?

Thanks
eric
 
sure... but you aren't talking about events... you are talking about
exceptions.
Events are thrown by an object that another object subscribes to.
Exceptions are propogated up to the caller, like you describe.

create a class, derived from System.Exception, and give it a name.
Then, when you want to throw your "event", create a new object of your type
and "throw" it.

For further information, see
http://msdn.microsoft.com/library/d.../html/frlrfSystemExceptionClassctorTopic1.asp

Hope this helps,
-- Nick
 
Thanks for all of the replies. I am familiar with
exceptions, i do want to raise an event. I have a
component that uses BeginReceive to monitor the message
queue, i want the component to raise an event to the
caller when there is a message in the queue. After a
little research i was able to get this figured out. It's
just a little more setup in C# vs. VB.

Thanks Again.
 
Back
Top