B.Habibzadeh B.Habibzadeh - 6 months ago 46
Vb.net Question

vb.net callback function to the anonymous

when i convert this line of code to vb.net:

monitor.CardInserted += (sender, args) => DisplayEvent("CardInserted", args);


and args parameter does not recognize by vb.net and I can't pass it to DisplayEvent sub.

Private Shared Sub DisplayEvent(eventName As String, unknown As CardStatusEventArgs)
MsgBox(">> {0} Event for reader: {1}", eventName, unknown.ReaderName)
MsgBox("ATR: {0}", BitConverter.ToString(If(unknown.Atr, New Byte(-1) {})))
MsgBox("State: {0}" & vbLf, unknown.State)
End Sub

Answer

The VB equivalent of that C# code is this:

AddHandler monitor.CardInserted, Sub(sender, args) DisplayEvent("CardInserted", args)

Presumably that's not the VB code you wrote so that would explain why it didn't work as it should. In future, show us the code that you did use so we can see what might be wrong with it.