0

I have a code generator that is generating C# functions called by an external DLL (when certain messages from the network are received).

My problem is that my main software is running in VB.NET, so I search a way to pass the function call from C# to VB.NET but without changing the C# code (or only a way a code generator could do it).

Does anyone has an idea?

This would be C# code:

namespace Csharp
{
   public class Test
   {
       System.Timers.Timer aTimer = new System.Timers.Timer();

       public Test()
       {
         aTimer.Elapsed += new System.Timers.ElapsedEventHandler(EventGeneratedInCsharp);
         aTimer.Interval = 5000;
         aTimer.Enabled = true;
        }

        public void EventGeneratedInCsharp(object source, System.Timers.ElapsedEventArgs e)
        {

        }
    }
}

I now need to forward the call to EventGeneratedInCsharp to my VB code. There is a reference from VB.NET to the C# DLL, but changing the C# code is not allowed (or only a way it can be automated). The C# code will also get results back he has to forward to the calling DLL again.

Any ideas? Delegate / Invoke / ... ???

Thanks - Martin.

  • Check this http://stackoverflow.com/questions/9342523/raiseevent-in-c-sharp – Morcilla de Arroz Dec 12 '16 at 09:49
  • I do not think if the question is clear, thus here is some source code to illustrate the problem: – Martin Weiss Dec 20 '16 at 06:53
  • I do not think if the question is clear, thus here is some source code to illustrate the problem: https://www.dropbox.com/s/hpn2isdhtjve90e/VB-CSharp-Crossing.jpg?dl=0 The task is to replace the VB comment with some code linking the C# timer call to the call of a VB function without changing the C# code part. – Martin Weiss Dec 20 '16 at 06:54
  • You need the C# code to call your VB code, but you can't change the C# code at all? Unless the existing C# code has some way to pass it a delegate to run or raises an event, I don't think what you're asking is possible. – Jeff B Dec 23 '16 at 17:00

0 Answers0