New to C# -- Events

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
 
N

Nick Malik

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
 
E

Eric

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.
 

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