• Advertisement
Sign in to follow this  

BeginInvoke event call to VB.NET

This topic is 2176 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to convert some C# event handling code to VB.NET using the online converters but they are not converting it correctly and I tried a few different ones.

public event PacAttachedDelegate OnPacAttached = null;
public event PacRemovedDelegate OnPacRemoved = null;

void PacAttachedCallback(int id)
{
m_numDevices++;

if (OnPacAttached != null)
m_ctrl.BeginInvoke(OnPacAttached, id);
}

void PacRemovedCallback(int id)
{
m_numDevices--;

if (OnPacRemoved != null)
m_ctrl.BeginInvoke(OnPacRemoved, id);
}


Converts to

Public Event OnPacAttached As PacAttachedDelegate = Nothing
Public Event OnPacRemoved As PacRemovedDelegate = Nothing

Private Sub PacAttachedCallback(id As Integer)
m_numDevices += 1

If OnPacAttached IsNot Nothing Then
m_ctrl.BeginInvoke(OnPacAttached, id)
End If
End Sub

Private Sub PacRemovedCallback(id As Integer)
m_numDevices -= 1

If OnPacRemoved IsNot Nothing Then
m_ctrl.BeginInvoke(OnPacRemoved, id)
End If
End Sub


Here are the errors I'm getting. I have searched over the web and tried different things but nothing works (for example I tried m_ctrl.BeginInvoke(New PacAttachedDelegate(AddressOf OnPacAttached), id))

Error 1 End of statement expected.
Error 2 End of statement expected.
Error 3 'Public Event OnPacAttached(id As Integer)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Error 4 'Public Event OnPacAttached(id As Integer)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Error 5 'Public Event OnPacRemoved(id As Integer)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

Share this post


Link to post
Share on other sites
Advertisement
VB.NET sucks doesn't it?

Unfortunately I have to have example code in several languages.

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
Could you tell us to what line the errors point?


VB.NET sucks doesn't it?

Why is that exactly?

Also, why don't you keep it in C#, then import it as an assembly in vb.net?

Share this post


Link to post
Share on other sites

Could you tell us to what line the errors point?


Error 1 and 2 are caused by the "= Nothing". The other errors are on the BeginInvoke lines.


Why is that exactly?


Just my opinion. Not a big fan of the syntax.


Also, why don't you keep it in C#, then import it as an assembly in vb.net?


No can do unfortunately. These are small examples for an SDK that p/invoke a native DLL for an LED controller. I provide examples in multiple languages. The callbacks are so you know when the device is plugged or unplugged. I use BeginInvoke so the callbacks are on the same thread as m_ctrl which is the main form.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement