PC Review


Reply
Thread Tools Rate Thread

BackgroundWorker problem when accessing a List in DoWork

 
 
schnandr
Guest
Posts: n/a
 
      15th Nov 2008
Hi,

I have a user control which contains ListView. I copy all
ListViewItems into a separate List<ListViewItem> called
unfilteredItems.
I am using a BackgroundWorker to filter the ListView. When I access
this list in the DoWork Handler I am getting an
InvalidOperationException that
the List was not created by this thread. Is there a way to solve this
problem?

Thanks for every hint
 
Reply With Quote
 
 
 
 
schnandr
Guest
Posts: n/a
 
      15th Nov 2008
Here some Code

public partial class ListCtrl : UserControl
{
private IListCtrlFilter filter;

private BackgroundWorker filterWorker;

private List<ListViewItem> unfilterdItems = new
List<ListViewItem>();

...

void filterWorker_DoWork(object sender, DoWorkEventArgs e)
{

BackgroundWorker worker = sender as BackgroundWorker;

List<ListViewItem> unfiltered = e.Argument as
List<ListViewItem>;

if filter;!= null)
{
listView.Items.Clear();
foreach (ListViewItem item in unfiltered)
{
if (worker.CancellationPending)
return;

if (filter.Include(item))
worker.ReportProgress(0, item);
}
}
}


void filterWorker_ProgressChanged(object sender,
ProgressChangedEventArgs e)
{
listView.Items.Add(e.UserState as ListViewItem);
}

...
}
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BackgroundWorker problem when accessing a List in DoWork schnandr Microsoft C# .NET 0 16th Nov 2008 07:06 AM
Exception when accessing backgroundWorker.CancellationPending Chris Microsoft C# .NET 2 26th Apr 2007 11:28 PM
BackgroundWorker Problem Chris Microsoft VB .NET 0 9th Apr 2007 03:51 AM
Problem accessing the LIST property of a listbox John T Ingato Microsoft Access Queries 1 27th Nov 2006 09:50 AM
System.ComponentModel.BackgroundWorker runs DoWork handler twice Ian Microsoft Dot NET Framework 0 19th Sep 2006 04:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:00 AM.