0

I have a VB.NET dll (written by someone else) and I require that it publishes and raises an event that will (typically) be handled by C#.

If the DLL were C# then this would be simple,

(client)
myDLL.OnClick += doClick

(Dll)
if (OnClick != null) OnClick(....

i.e. 2 lines of code

but perhaps it's my frustration at VB.NET, but I cannot find a simple example of how to do this.

Can someone please show/explain how to define and raise an event in VB.NET, that can be handled within C#?

Thanks

MM

0

2 Answers 2

2

I've just tested this and its exactly the same as it normally is - raise the event in VB.Net (as you normally would)

Public Class Class1
    Public Event TestEvent()

    Public Sub RaiseTestEvent()
        RaiseEvent TestEvent()
    End Sub
End Class

Then reference the VB.Net assembly and consume the event in C# (again, as you normally would)

var class1 = new ClassLibrary1.Class1();
class1.TestEvent += () => Console.WriteLine("Test Event");
class1.RaiseTestEvent();

See Raising Events and Responding to Events

Sign up to request clarification or add additional context in comments.

Comments

0

VB Uses the Event keyword.

Public Event SomethingChanged (byval sender as object, e as eventargs)

Subscribe to it in C# as you would any other event.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.