locked
InvokeRequired not working in VB 2010 RRS feed

  • Question

  • This code works fine in VB 2008 attempting to redo the program in vb2010:

    in the GuiForm:

    the following is declared in formgui:

     Private Delegate Sub UpDateGSLDelegate(ByVal rpn As Integer)

    Also the following sub is also in formgui:

     Public Sub updateGSLDisplay(ByVal rpn As Integer)
            Try
                If FormGUI.InvokeRequired Then
                    Invoke(New UpDateGSLDelegate(AddressOf UpDateTheGSL), rpn)
                Else
                    UpDateTheGSL(rpn)
                End If
            Catch ex As Exception
            End Try

    end sub

    " updateGSLDisplay" is called from this sub in Module1:

    Public Sub UpdateGSL(ByVal GSLValue As String, ByVal RPN As Integer, ByVal xSleep As Integer)
            If Not Form_GUI.IsDisposed Then
                FormGUI.updateGSLDisplay(RPN)
                System.Threading.Thread.Sleep(xSleep)
            End If
        End Sub

    "UpdateGSL", in turn, will be called from any subs running in another module in a separate thread.

    The purpose is to update one or more labels on formgui based on the "rpn" variable

    now the program will just hang at " Invoke(New UpDateGSLDelegate(AddressOf UpDateTheGSL), rpn)" in the "updateGSLDisplay" sub. no error messages, just stops.

     

    also I'm now using the " Dim t1 As Task = Task.Factory.StartNew(Sub()" way to starting a new thread in case that is revelant.

    what has changed from 2008 to 2010 to cause this. Just started trying out vb 2010? How can I fix this in 2010?

    I looked at this page: http://msdn.microsoft.com/en-us/library/cc714070.aspx but it doesn't say anything or maybe it does and I just didn't pickup on it.

     

     

    Thank you very much for any help

    Sunday, February 6, 2011 10:55 PM

Answers

  • Invoke(New UpDateGSLDelegate(AddressOf updateGSLDisplay), rpn)
    • Proposed as answer by spotty Monday, February 7, 2011 7:52 PM
    • Marked as answer by jlcjlee Monday, February 7, 2011 11:18 PM
    Sunday, February 6, 2011 11:56 PM

All replies

  • Invoke(New UpDateGSLDelegate(AddressOf updateGSLDisplay), rpn)
    • Proposed as answer by spotty Monday, February 7, 2011 7:52 PM
    • Marked as answer by jlcjlee Monday, February 7, 2011 11:18 PM
    Sunday, February 6, 2011 11:56 PM
  • Thank you!!!

    That fixed it!

     

     

    • Marked as answer by jlcjlee Monday, February 7, 2011 11:18 PM
    • Unmarked as answer by jlcjlee Monday, February 7, 2011 11:18 PM
    Monday, February 7, 2011 7:25 PM