Passing Parameters using Invoke in multi-threaded app

P

Phillip Taylor

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 ConversionUpdateComplete(ByRef records As LinkedList(Of
ListViewItem))
If (Me.InvokeRequired) Then
Dim method As New MigrationCompleteEventHandler(AddressOf
ConversionUpdateComplete)
Me.Invoke(method, New Object() {records})
Else

lvUpdateSuggestions.Items.Clear()

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

lvUpdateSuggestions.View = True

pbConverting.Visible = False
lblConversionWait.Visible = False
lblSuggestionNotice.Visible = True
btnNext.Enabled = True
End If
End Sub
 
G

Guest

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.
 
A

Armin Zingler

Phillip Taylor said:
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 ConversionUpdateComplete(ByRef records As
LinkedList(Of ListViewItem))
If (Me.InvokeRequired) Then
Dim method As New MigrationCompleteEventHandler(AddressOf
ConversionUpdateComplete)
Me.Invoke(method, New Object() {records})
Else

lvUpdateSuggestions.Items.Clear()

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

lvUpdateSuggestions.View = True

pbConverting.Visible = False
lblConversionWait.Visible = False
lblSuggestionNotice.Visible = True
btnNext.Enabled = True
End If
End Sub


Armin
 
M

Michel Posseth [MCP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top