malai.kuangren
malai.kuangren

Reputation: 359

Multiple Thread Access a Collection

Supposed there is collection which is accessed by multiple thread. One of thread needs to know a given item had been added by another thread. Can anyone give a solution to make it ? Thanks.

Upvotes: 0

Views: 122

Answers (1)

paparazzo
paparazzo

Reputation: 45106

Start with a thread safe collection

Thread-Safe Collections

As for knowing what thread added specific item I don't think an item tracks the tread. I think you could add a Property TheadName and have the thread enter that value.

The question states "specific item had been added". Then in comment the OP infers any item.

.NET does not have thread safe ObservableCollection. There are some on codeplex or possible rethink you design. ConcurrentQueue may be an option.

Upvotes: 1

Related Questions