Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Events in .NET Between VB and C#

Posted on 2011-09-08
4
Medium Priority
?
344 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

609 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