Raise event problem (c# to vb)

camberman

New member
Joined
Jan 26, 2012
Messages
4
Programming Experience
Beginner
Spent 3 days on and off with this one so I figure it's time to ask for assistance :)

Converting some code from C# to vb (wpf), and now getting a message that I cannot call an event directly and must use "RaiseEvent". I've tried various permutations using addhandler, yet having no luck. Any help would be greatly appreciated.

This is the code as the converter presented it to me, minus irrelevant lines.
VB.NET:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] wrapper [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]SdkWrapper

wrapper = New SdkWrapper()

  wrapper.SessionInfoUpdated += New EventHandler(Of SdkWrapper.SessionInfoUpdatedEventArgs)(wrapper_SessionInfoUpdated)

Private Sub wrapper_SessionInfoUpdated(sender As Object, e As SdkWrapper.SessionInfoUpdatedEventArgs)

end sub

[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

This is the original C# below, minus irrelevant lines.


VB.NET:
 private SdkWrapper wrapper;

 wrapper = new SdkWrapper();

            wrapper.SessionInfoUpdated += new EventHandler<SdkWrapper.SessionInfoUpdatedEventArgs>(wrapper_SessionInfoUpdated);

 private void wrapper_SessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e)
{
}
 
The code is adding event handler, use AddHandler statement: AddHandler Statement
WithEvent and Handles clause also looks like it applies: Handles Clause (Visual Basic)

Ok, so something like this for the addhandler, which doesn't throw any errors but doesn't still doesn't quite get me there.

VB.NET:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]AddHandler[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] wrapper.SessionInfoUpdated, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]AddressOf[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] wrapper_SessionInfoUpdated[/SIZE][/FONT][/SIZE][/FONT]

Still having a bit of trouble deciphering the part where or how it makes the call to this

VB.NET:
[FONT=Consolas][SIZE=2][COLOR=#2b91af]Private Sub wrapper_SessionInfoUpdated(sender As Object, e As SdkWrapper.SessionInfoUpdatedEventArgs)

end sub
[/COLOR][/SIZE][/FONT]
 
Still plugging away at this, and did get the sub to fire using "wrapper.Start()" under the
VB.NET:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]AddHandler[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] wrapper.SessionInfoUpdated, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]AddressOf[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] wrapper_SessionInfoUpdated[/SIZE][/FONT][/SIZE][/FONT]
Is this proper?
 
Is this proper?
That's how AddHandler statement is used.
Still having a bit of trouble deciphering the part where or how it makes the call to this (wrapper_SessionInfoUpdated)
Events are raised using RaiseEvent statement, which invokes all associated event handlers.
 
Back
Top