简体   繁体   中英

How to receive an event in c# which is raised in vb?

I need to use a legacy library written in visual basic which raises some events. Actually I do not know how to bind an action in my new c# project if one of the events are raised.

The event in the legacy code is defined like this

Public Event OnStartOfMainLoop(ByRef evt As HandlerEvent, ByVal datapath As String, ByRef skipRun As Boolean, ByRef refreshQueueMap As Boolean, ByRef refreshFormsMap As Boolean)

and raised

RaiseEvent OnStartOfMainLoop(evt, datapath, skipRun, refreshQueueMap, refreshFormsMap)

Now how can I receive this event in my new project and handle it?

Within C#, you simply need to subscribe to the event:

obj.OnStartOfMainLoop += MyEventHandlerMethod;

public void MyEventHandlerMethod(ref HandlerEvent evt, string datapath,
        ref bool skipRun, ref bool refreshQueueMap, ref bool refreshFormsMap)
{
    //Handle the event here
}

Where obj is the instance of the object you are subscribing to, and MyEventHandlerMethod is the method you want to route it to.

You will need to ensure that the handler method correctly implements the required signature of your event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM