G
G
govnokoder2014-11-14 21:08:59
C++ / C#
govnokoder, 2014-11-14 21:08:59

Why does NotSupportedException fall in cycles?

Inside the loops (and foreach, and for, and while), a NotSupportedException is thrown with the description:
"This type of CollectionView does not support changes to its SourceCollection from a thread other than the Dispatcher thread."
In foreach - a regular List<> list, in for and while there shouldn't be any CollectionView at all. What could it be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Sydorenko, 2014-11-14
@San40

You are trying to modify a collection (delete?) that does not imply deletion in the place where you do it. Cycle code which accepts? where is it located? UI thread event handler?

L
lam0x86, 2014-11-15
@lam0x86

CollectionView is created automatically in WPF when binding collections, so there is nothing strange here. The problem is most likely that you are modifying your collection on a non-UI thread, for example by creating a Task and not specifying a Scheduler, or using a timer other than a DispatcherTimer, etc. The easiest way to solve the problem is to wrap the code that changes collection, into a call to Dispatcher.Invoke(...). The main thing is to specify the correct Dispatcher - it can be obtained from any window control.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question