P
Phillip Taylor
I have an application which displays a ListView control on a form. I
start a second thread to run in the background and populate the
control. When the second thread finishes it's work, it invokes a
method which should populate the control. When I perform the
callback / procedure call it passes a LinkedList as a parameter, which
doesn't convert into an Object array properly. Even though i can't see
why it wouldn't. The line "me.invoke(method, New Object() { records })
crashes the problem with:
"The value of argument 'value' (-1) is invalid for Enum type 'View'.
Parameter name: value"
My code looks like this:
--DELEGATE
Public Delegate Sub MigrationCompleteEventHandler(ByVal records As
LinkedList(Of ListViewItem))
--IN SECOND, CALLING THREAD
processComplete.Invoke(returnedListViewItems)
--UNDER FORM, IN ORIGINAL THREAD
Public Sub ConversionUpdateComplete(ByRef records As LinkedList(Of
ListViewItem))
If (Me.InvokeRequired) Then
Dim method As New MigrationCompleteEventHandler(AddressOf
ConversionUpdateComplete)
If (records.Count > 0) Then
Me.Invoke(method, New Object() {records}) <-- THIS
DOEN'T WORK.
End If
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
start a second thread to run in the background and populate the
control. When the second thread finishes it's work, it invokes a
method which should populate the control. When I perform the
callback / procedure call it passes a LinkedList as a parameter, which
doesn't convert into an Object array properly. Even though i can't see
why it wouldn't. The line "me.invoke(method, New Object() { records })
crashes the problem with:
"The value of argument 'value' (-1) is invalid for Enum type 'View'.
Parameter name: value"
My code looks like this:
--DELEGATE
Public Delegate Sub MigrationCompleteEventHandler(ByVal records As
LinkedList(Of ListViewItem))
--IN SECOND, CALLING THREAD
processComplete.Invoke(returnedListViewItems)
--UNDER FORM, IN ORIGINAL THREAD
Public Sub ConversionUpdateComplete(ByRef records As LinkedList(Of
ListViewItem))
If (Me.InvokeRequired) Then
Dim method As New MigrationCompleteEventHandler(AddressOf
ConversionUpdateComplete)
If (records.Count > 0) Then
Me.Invoke(method, New Object() {records}) <-- THIS
DOEN'T WORK.
End If
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