我目前有一个用C#编写的示例应用程序,我想在我的VB.NET项目中使用它的代码。现在,我试图复制的功能看起来像这样:
private void Start(CardInfo networkCard, IEnumerable<int> universes)
{
socket = new StreamingAcnSocket(Guid.NewGuid(), "Streaming ACN Snoop");
socket.NewPacket += new EventHandler<NewPacketEventArgs<Acn.Packets.sAcn.StreamingAcnDmxPacket>>(socket_NewPacket); //This is the line I'm having trouble with
socket.Open(networkCard.IpAddress);
foreach (int universe in universes)
socket.JoinDmxUniverse(universe);
dmxOutput = new DmxStreamer(socket);
dmxOutput.AddUniverse(sendData.Universe);
acnPortExplorer = new RdmNetEndPointExplorer();
acnPortExplorer.LocalAdapter = networkCard.IpAddress;
acnPortExplorer.NewEndpointFound += acnPortExplorer_NewEndpointFound;
acnPortExplorer.Start();
}
这是我到目前为止的VB代码:
Private Sub Start(networkCard As CardInfo, universes As IEnumerable(Of Integer))
socket = New StreamingAcnSocket(Guid.NewGuid(), "Streaming ACN Snoop")
''yet to convert this line
socket.Open(networkCard.IpAddress)
For Each universe As Integer In universes
socket.JoinDmxUniverse(universe)
Next
dmxOutput = New DmxStreamer(socket)
dmxOutput.AddUniverse(sendData.Universe)
acnPortExplorer = New RdmNetEndPointExplorer()
acnPortExplorer.LocalAdapter = networkCard.IpAddress
acnPortExplorer.NewEndpointFound += acnPortExplorer_NewEndpointFound
acnPortExplorer.Start()
End Sub
我试图将此功能转换为VB。我已经设法在一个在线代码转换器的帮助下转换了几乎所有东西。但是,我仍然无法弄清楚如何将第4行转换为VB。
如果重要,这是来自ACN上的StreamingACN示例项目的codeplex(https://acn.codeplex.com/)。
我很感激我能得到任何帮助。谢谢!
答案 0 :(得分:0)
如果你的意思是这一行:
socket.NewPacket += new EventHandler<NewPacketEventArgs<Acn.Packets.sAcn.StreamingAcnDmxPacket>>(socket_NewPacket);
你可以这样做:
AddHandler socket.NewPacket, AddressOf socket_NewPacket
这会将事件处理程序附加到socket
实例,转发对方法socket_NewPacket
的调用。所有EventArgs的东西现在都是方法socket_NewSocket
的关注点,所以你应该注意签名:
Public Sub socket_NewSocket(sender As Object, args As NewPacketEventArgs(Of Acn.Packets.sAcn.StreamingAcnDmxPacket))
' your code goes here
End Sub