Hi!

I want to run multiple threads at the same time, and each thread has foreach loop accessing a listbox, so each thread checks every item in listbox, instead that each thread checks only one item, or skip an item if it has already been checked by other thread.
Now, i would like to syncronize them so each thread checks only one item, which has not been checked by any other thread previously

Thanks for any help in advance!

Recommended Answers

All 2 Replies

You'll need some sort of indicator that tells a thread that the item has already been checked, and a locking mechanism to prevent the threads from attempting to access that same object.

You should probably read this.

well, i already tried to make a global String which was supposed to hold the last used item, and if current item is in that variable, it gets added to another listbox
however, that didnt work as i expected it to work; it instantly added all unchecked items to checked list, and resumed again, but with only one thread

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.