Passing Parameters using Invoke in multi-threaded app

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phillip Taylor

    #1

    Passing Parameters using Invoke in multi-threaded app

    I'm having a problem with this code. I can't really understand why it
    won't work if, for example, I pass in a linked list of 0 records.

    Public Sub ConversionUpdat eComplete(ByRef records As LinkedList(Of
    ListViewItem))
    If (Me.InvokeRequi red) Then
    Dim method As New MigrationComple teEventHandler( AddressOf
    ConversionUpdat eComplete)
    Me.Invoke(metho d, New Object() {records})
    Else

    lvUpdateSuggest ions.Items.Clea r()

    For Each l As ListViewItem In records
    lvUpdateSuggest ions.Items.Add( l)
    Next

    lvUpdateSuggest ions.View = True

    pbConverting.Vi sible = False
    lblConversionWa it.Visible = False
    lblSuggestionNo tice.Visible = True
    btnNext.Enabled = True
    End If
    End Sub

  • Spam Catcher

    #2
    Re: Passing Parameters using Invoke in multi-threaded app

    Phillip Taylor <Phillip.Ross.T aylor@gmail.com wrote in
    news:1184690177 .951521.76660@g 12g2000prg.goog legroups.com:
    I'm having a problem with this code. I can't really understand why it
    won't work if, for example, I pass in a linked list of 0 records.

    In anycase, what is happening in your app?

    You should use BeginInvoke instead. Invoke may deadlock your app under
    load.


    Public Sub ConversionUpdat eComplete(ByRef records As LinkedList(Of
    ListViewItem))
    If (Me.InvokeRequi red) Then
    Dim method As New MigrationComple teEventHandler( AddressOf
    ConversionUpdat eComplete)
    Me.Invoke(metho d, New Object() {records})
    Else
    >
    lvUpdateSuggest ions.Items.Clea r()
    >
    For Each l As ListViewItem In records
    lvUpdateSuggest ions.Items.Add( l)
    Next
    >
    lvUpdateSuggest ions.View = True
    >
    pbConverting.Vi sible = False
    lblConversionWa it.Visible = False
    lblSuggestionNo tice.Visible = True
    btnNext.Enabled = True
    End If
    End Sub
    >
    >

    Comment

    • Armin Zingler

      #3
      Re: Passing Parameters using Invoke in multi-threaded app

      "Phillip Taylor" <Phillip.Ross.T aylor@gmail.com schrieb
      I'm having a problem with this code. I can't really understand why
      it won't work if, for example, I pass in a linked list of 0 records.
      What does "won't work" mean? The code looks ok (although I don't know why
      the arg is declared ByRef).
      Public Sub ConversionUpdat eComplete(ByRef records As
      LinkedList(Of ListViewItem))
      If (Me.InvokeRequi red) Then
      Dim method As New MigrationComple teEventHandler( AddressOf
      ConversionUpdat eComplete)
      Me.Invoke(metho d, New Object() {records})
      Else
      >
      lvUpdateSuggest ions.Items.Clea r()
      >
      For Each l As ListViewItem In records
      lvUpdateSuggest ions.Items.Add( l)
      Next
      >
      lvUpdateSuggest ions.View = True
      >
      pbConverting.Vi sible = False
      lblConversionWa it.Visible = False
      lblSuggestionNo tice.Visible = True
      btnNext.Enabled = True
      End If
      End Sub
      >

      Armin

      Comment

      • Michel Posseth  [MCP]

        #4
        Re: Passing Parameters using Invoke in multi-threaded app

        I have seern lots of strange behavior of .net apps when used byref
        parameters , as i also do not see the point why it should be passed byref in
        this case , i recomend you to declare the parameter byval and try again it
        might / or might not solve your problem :-)


        Regards

        Michel Posseth


        "Armin Zingler" <az.nospam@free net.deschreef in bericht
        news:%23LkqBaJy HHA.4672@TK2MSF TNGP02.phx.gbl. ..
        "Phillip Taylor" <Phillip.Ross.T aylor@gmail.com schrieb
        >I'm having a problem with this code. I can't really understand why
        >it won't work if, for example, I pass in a linked list of 0 records.
        >
        What does "won't work" mean? The code looks ok (although I don't know why
        the arg is declared ByRef).
        >
        > Public Sub ConversionUpdat eComplete(ByRef records As
        >LinkedList(O f ListViewItem))
        > If (Me.InvokeRequi red) Then
        > Dim method As New MigrationComple teEventHandler( AddressOf
        >ConversionUpda teComplete)
        > Me.Invoke(metho d, New Object() {records})
        > Else
        >>
        > lvUpdateSuggest ions.Items.Clea r()
        >>
        > For Each l As ListViewItem In records
        > lvUpdateSuggest ions.Items.Add( l)
        > Next
        >>
        > lvUpdateSuggest ions.View = True
        >>
        > pbConverting.Vi sible = False
        > lblConversionWa it.Visible = False
        > lblSuggestionNo tice.Visible = True
        > btnNext.Enabled = True
        > End If
        > End Sub
        >>
        >
        >
        Armin

        Comment

        Working...