InvokeRequired not working with my Timer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Denardo

    #1

    InvokeRequired not working with my Timer

    Hey all, I'm having a problem with the following:

    Private m_myDELEGATE As New myDELEGATE(Addr essOf
    ReceivingServer Message_UIThrea d)
    Delegate Sub myDELEGATE(ByVa l ReceivingServer Message As NetworkMessage)

    Public Sub ReceivingServer Message(ByVal objNetworkMessa ge As NetworkMessage)
    If (Me.InvokeRequi red) Then
    Dim args() As Object = {objNetworkMess age}
    Me.Invoke(m_myD ELEGATE, args)
    Else
    ReceivingServer Message_UIThrea d(objNetworkMes sage)
    End If
    End Sub

    Basically I use this method to pass control from a worker thread back to the
    UI Thread. It works fine if its a normal thread, but when I use a timer and
    call this method after the timer elapses, then Me.InvokeRequir ed = False and
    it treats it likes its already on the main thread, and thus when I get in
    ReceivingServer Message_UIThrea d, I'm getting the all to familiar
    "Cross-Thread operation not valid" error.

    I thought Timers were just special cases of threads. What is going on
    and/or what do I need to do to correct my problem?


  • Mark Denardo

    #2
    Re: InvokeRequired not working with my Timer

    Sorry I jumped the gun...my thread is also making Me.InvokeRequir ed return
    False. It must be something else I changed. I'll have to investigate more.

    Sorry Disregard....fo r now.


    "Mark Denardo" <markdenardo@ru nbox.com> wrote in message
    news:ds-dndS_JcnZvs3ZRV n-vw@starstream.n et...[color=blue]
    > Hey all, I'm having a problem with the following:
    >
    > Private m_myDELEGATE As New myDELEGATE(Addr essOf
    > ReceivingServer Message_UIThrea d)
    > Delegate Sub myDELEGATE(ByVa l ReceivingServer Message As NetworkMessage)
    >
    > Public Sub ReceivingServer Message(ByVal objNetworkMessa ge As
    > NetworkMessage)
    > If (Me.InvokeRequi red) Then
    > Dim args() As Object = {objNetworkMess age}
    > Me.Invoke(m_myD ELEGATE, args)
    > Else
    > ReceivingServer Message_UIThrea d(objNetworkMes sage)
    > End If
    > End Sub
    >
    > Basically I use this method to pass control from a worker thread back to
    > the UI Thread. It works fine if its a normal thread, but when I use a
    > timer and call this method after the timer elapses, then Me.InvokeRequir ed
    > = False and it treats it likes its already on the main thread, and thus
    > when I get in ReceivingServer Message_UIThrea d, I'm getting the all to
    > familiar "Cross-Thread operation not valid" error.
    >
    > I thought Timers were just special cases of threads. What is going on
    > and/or what do I need to do to correct my problem?
    >[/color]


    Comment

    Working...