I have been working very hard on figuring this out and just can’t understand the events. Can someone help me understand the event process in my code? Or tell me why my image won’t switch when it runs the code?
Declarations of Class and members
Partial Public Class Name
Implements IChat
Private member As String
Private instanceContext As InstanceContext
Private participant As IChatChannel
Private ostat As IOnlineStatus
Private factory As DuplexChannelFactory(Of IChatChannel)
Inside my Connect Sub
'Construct InstanceContext to handle messages on callback interface.
' An instance of ChatApp is created and passed to the InstanceContext.
instanceContext = New InstanceContext(Me)
' Create the participant with the given endpoint configuration
' Each participant opens a duplex channel to the mesh
' participant is an instance of the chat application that has opened a channel to the mesh
factory = New DuplexChannelFactory(Of IChatChannel)(instanceContext, "ChatEndpoint")
participant = factory.CreateChannel()
' Retrieve the PeerNode associated with the participant and register for online/offline events
' PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes.
ostat = participant.GetProperty(Of IOnlineStatus)()
AddHandler ostat.Online, AddressOf Me.OnOnline
AddHandler ostat.Offline, AddressOf Me.OnOffline
Sub routines that are supposed to change image
Public Sub Join(ByVal member As String) Implements IChat.Join
instanceShellProp.imgP2P.Image = Namespace.My.Resources.Offline
MsgBox("JOINED OFFLINE")
End Sub
Public Sub Leave1(ByVal member As String) Implements IChat.Leave
instanceShellProp.imgP2P.Image = Namespace.My.Resources.Disconnected
MsgBox("NOT CONNECTED")
End Sub
Public Sub OnOnline(ByVal sender As Object, ByVal e As EventArgs)
instanceShellProp.imgP2P.Image = Namespace.My.Resources.Online
MsgBox("JOINED ONLINE")
End Sub
Public Sub OnOffline(ByVal sender As Object, ByVal e As EventArgs)
instanceShellProp.imgP2P.Image = Namespace.My.Resources.Offline
MsgBox("JOINED OFFLINE")
End Sub
instanceShellProp returns the instance of the Shell that is a MDI container.
All of the images are in the Resources and properly spelled and referenced to. The MessageBox will pop up but the images won’t change, EXCEPT on Join.
I’m not trying to Code Dump, just trying to make sure that you can see what I am looking at and allow you to give better advice.
All help is appreciated!
EDIT
Okay, I find this weird… I feel like I am getting close. When the messagebox is not commented out the image will change, when it is commented out the image doesn’t change.
Any better suggestions on how to get this to work?
Public Sub OnOnline(ByVal sender As Object, ByVal e As EventArgs)
With instanceShellProp.imgP2P
.Image = Nothing
.Visible = True
End With
'MsgBox("JOINED ONLINE")
With instanceShellProp.imgP2P
.Image = Namespace.My.Resources.Online
.Visible = True
End With
End Sub
Added Application.DoEvents() and it allowed it to work. Not sure as to why but if someone could explain that would be awesome! Thanks!