Cross-threading with backgroundworker - passing listview

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
 
A

AlexS

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
 
C

cpix via DotNetMonster.com

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]
 

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