Windows Forms Invoke Required

47 views
Skip to first unread message

george.n...@hotmail.com

unread,
Apr 3, 2013, 11:10:50 AM4/3/13
to web...@googlegroups.com
Hi,

I am trying to implement a VB project in Windows Forms and after successfully receiving the client connect event to alert the user by changing the text on a label on the form and the color of an informative image from red to green.

I was using an xmpp library, that I am trying to replace with websync, and the library provided some very convenient object handlers that made invoking very easy. For example on the login xmpp event:

Private Sub myXMPP_OnLogin(sender As Object) Handles myXMPP.OnLogin
        If InvokeRequired Then
            BeginInvoke(CType(AddressOf myXMPP_OnLogin, agsXMPP.ObjectHandler), New Object() {sender})
            Return
        End If

        rle_FormSatus.Text = "Connected to Data Server BOSH"
        rib_XMPP.BackColor = Color.DarkGreen
    End Sub

Can you please suggest a proper way for a VB project to implement the same functionality?

Kind Regards,

George

Anton Venema

unread,
Apr 3, 2013, 11:49:38 AM4/3/13
to web...@googlegroups.com
Hi George!

The InvokeRequired/BeginInvoke methods are part of WinForms, so you can use them with WebSync the same way you would with any other library.

Private Sub Connect()
client.Connect(New ConnectArgs() With { _
.OnSuccess = ConnectSuccess _
})
End Sub

Private Sub ConnectSuccess(e As ConnectSuccessArgs)
If InvokeRequired Then
BeginInvoke(ConnectSuccess, New () { e })
Return
End If

' update the UI here
End Sub

Anton Venema
Frozen Mountain Software
604-227-2458 (Canada)
919-300-5520 (United States)
888-379-6686 (Extension 
102)
www.frozenmountain.com




--
You received this message because you are subscribed to the Google Groups "WebSync" group.
To unsubscribe from this group and stop receiving emails from it, send an email to websync+u...@googlegroups.com.
To post to this group, send email to web...@googlegroups.com.
Visit this group at http://groups.google.com/group/websync?hl=en.
To view this discussion on the web visit https://groups.google.com/d/msg/websync/-/CT6ZZLhmKaoJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

george.n...@hotmail.com

unread,
Apr 4, 2013, 6:43:42 AM4/4/13
to web...@googlegroups.com
I was thinking something along the lines you proposed, unfortunately the provided sample does not compile.

e.g. the suugested line  in your code

BeginInvoke(ConnectSuccess, New () { e })   

is giving a number of compile errors.

Anton Venema

unread,
Apr 4, 2013, 11:26:12 AM4/4/13
to web...@googlegroups.com
VB can be a bit nitpicky at times. I think you have the general idea, so here are some examples on how to use InvokeRequired/BeginInvoke from VB:


Anton Venema
Frozen Mountain Software
604-227-2458 (Canada)
919-300-5520 (United States)
888-379-6686 (Extension 
102)
www.frozenmountain.com



To view this discussion on the web visit https://groups.google.com/d/msg/websync/-/-0-iEYQuJ3sJ.
Reply all
Reply to author
Forward
0 new messages