Cross-threading with backgroundworker - passing listview

  • Thread starter Thread starter cpix
  • Start date Start date
C

cpix

hi!

i've been reading alot about the backgroundworker, but most of the articals
only shows that you can use the progress-event to send a message to the form.
Im trying to pass a listview with
a number of strings (in this case, strings of files and directorys).
i thought it could be done like this,

bwbackup.RunWorkerAsync(lvBackupStatus);
ListView lvibwc = (ListView) e.Argument;

but for some reason while running dowork I get a cross thread error.

Any tip taken, thanks!

-pixlor
 
You should leave controls on UI thread to avoid issues like that one

Instead pass data for listview - you can use arrays, lists, tables, custom
tailored structures etc. For example, you can pass between threads arrays of
ListViewItem and additional values specifying how to show them. Just don't
touch UI control properties or methods in non-UI threads.

HTH
 
Thanks, arrays worked fine :)

- Eivind
You should leave controls on UI thread to avoid issues like that one

Instead pass data for listview - you can use arrays, lists, tables, custom
tailored structures etc. For example, you can pass between threads arrays of
ListViewItem and additional values specifying how to show them. Just don't
touch UI control properties or methods in non-UI threads.

HTH
[quoted text clipped - 14 lines]
 
Back
Top