Background Worker + Cross-Thread Calls

Cheetah

Well-known member
Joined
Oct 12, 2006
Messages
232
Programming Experience
Beginner
Hi there,

How would i make a cross-thread call to get the value of a listviewitem, then delete it.

I have managed to do an example where i set the text of the textbox, but I couldn't do this one.

I don't think its possible to do what i want with the progress report by the background worker as i need it to do this before continuing on, but the report progress seems to do it at the same time.

Thanks.
 
The BackgroundWorker simplifies a lot of multi-threading scenarios but it can't do everything. If you don't want to, or can't, use the ReportPorgress/ProgressChanged option then you do what's always been done to access controls from worker threads: use delegation, e.g.
VB.NET:
Private Delegate Sub RemoveListViewItemInvoker(ByVal index As Integer)

Private Sub RemoveListViewItem(ByVal index As Integer)
    If Me.ListView1.InvokeRequired Then
        'We are on a worker thread so delegate.
        Me.ListView1.Invoke(New RemoveListViewItemInvoker(AddressOf RemoveListViewItem), _
                            index)
    Else
        'We are on the UI thread so access the control.
        Me.ListView1.Items.RemoveAt(index)
    End If
End Sub
Now just call that method and it takes care of the rest.
 
Thanks I figured it out anyways - it was just my understanding of how the cross-thread call worked.

Thanks anyways!
 
Back
Top