?
Solved

Events in .NET Between VB and C#

Posted on 2011-09-08
4
Medium Priority
?
340 Views
Last Modified: 2013-11-08
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.
0
Comment
Question by:crazedsanity
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 total points
ID: 36503991
When coding in one .Net language treat all class library calls as if it is the same language. For example, if you have an event "OnStart" in you C# class library, then to wire it up in VB.Net:

AddHandler myClassObject.OnStart, AddressOf MyEventHandlerFunction
0
 
LVL 9

Author Comment

by:crazedsanity
ID: 36504148
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).
0
 
LVL 28

Expert Comment

by:strickdd
ID: 36504305
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.
0
 
LVL 9

Author Closing Comment

by:crazedsanity
ID: 36504684
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!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question