Link to home
Start Free TrialLog in
Avatar of crazedsanity
crazedsanityFlag for United States of America

asked on

Events in .NET Between VB and C#

I have a codebase that has mixed VB.NET and C#: it is slowly being rewritten into purely C#, but for now it has to be mixed.  Unfortunately, this has left me with a situation where a C# library that has events needs to communicate those events to a form application written in C#.

I have plenty of programming experience, both with VB.net and C#, but I haven't really gotten into the intricacies of events, especially between the two languages.  I've managed to wire-up events strictly in VB, and the same with C# (once or twice each)... but not across the two.

I'm looking for examples.  The basics are:
 * Form application in VB, displays "what's going on" to the user
 * C# library, firing events that indicate what's going on
 * need the VB app to handle the C# events

I don't know if this is possible.  Pointers are welcome, but please don't waste time focusing on the mixed environment unless doing so will result in real progress.
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of crazedsanity

ASKER

Thanks for the info.  I have the VB code listening to the events, but the text isn't getting sent... I'm not really sure where to debug.

Is there an example of creating an event and event handler in C# that will allow a string to be sent?  It seems my C# is sending events that something has happened, but I'm not the text.

The C# code was originally for a console application that initializes a database.  I've adapted it somewhat, and I have events firing (I think), but the text doesn't get sent.  On the console, it writes things like:
Initializing content for language en-GB
 -- created 5432 records in 12.3 seconds
initializing content for language fr
 -- created 5432 records in 12.3 seconds

Open in new window


That info doesn't seem to get sent.  I've tried to put the last message into a variable to check... but that seems wrong (not to mention it doesn't actually work).
Open both project in the same solution, set some break points where you fire the events and in the event handlers and see if C# is raising the event and if VB is handling the event.
The part that I was missing was that the event in C# was using the standard "EventArgs" class, while the method (in VB) that was updating the screen used a custom "UpdateStatusEventArgs" class.  By implementing that class in C# (taking the code and converting to C# using http://www.developerfusion.com/tools/convert/vb-to-csharp/), I was able to pass a string in the notification.  Sometimes it's difficult to see the forest through all them trees...

Thanks for the help, strickdd!