ComboBox takes way too long to open (COMException Error)

Here is the situation of my problem:
I have a ListBox with two items of type MyClass .
MyClass has a List<Column> collection.
Somewhere else in the same window I have a ComboBox with the columns of the selected MyClass.ColumnCollection as ItemsSource.

Here is where the trouble starts:
The first time i open the popup of the ComboBox everything goes fine.
When I select an other item in the ListBox (and also changing the ComboBox source) it takes longer than 10 seconds to open the popup. If it takes longer than 60 seconds I get the following error:

The CLR has been unable to transition from COM context 0xf13d90 to COM context 0xf13fe0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

I Googled for the error and everywhere I came it was the advice to disable the throwing of ContextSwitchDeadlocks which is no solution at all!

I looked further into this and found the following COMException:

An event was unable to invoke any of the subscribers (Exception from HRESULT: 0x80040201)

I don't use threads/tasks or whatever, just a binding on the ComboBox .
I tried to refresh the ItemsSource at the selection of another item, but it made no difference since it was already set correctly.

I tried to google for this error, but it seems there is no solution for this problem.
Microsoft offered a hotfix for this, but there is no download.

Code for the ListBox:

    <ListBox Margin="468,30,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="420" Width="410"
                            ItemsSource="{Binding ElementName=Window, Path=MyClassItems}"
                            SelectedItem="{Binding ElementName=Window, Path=MyClassItem}"
                            DisplayMemberPath="Name" />

Code for the ComboBox:

        <ComboBox Margin="580,490,0,0" Width="300"
                            VerticalAlignment="Top" HorizontalAlignment="Left" DisplayMemberPath="Name"
                            ItemsSource="{Binding ElementName=Window, Path=MyClassItem.Columns}"
                            SelectedItem="{Binding ElementName=Window, Path=MyClassItem.Column, Mode=OneWay}" SelectionChanged="SelectedColumn_SelectionChanged" />

SelectionChanged Event:

MyClassItem.Column = (sender as Combobox).SelectedValue as Column;

Questions:
Does anybody know how to prevent the COMException?

Update 1:
Added some Xaml code samples

Update 2:
Simplified the question(s)

Update 3:
I found out that the real error is the COM exception.
Updated my question with the new info.

Update 4:
All the object in the ListBox are complete and present in memory so there is no querying going one. Moreover, the waiting time always occurs no matter if the comboBox is filled with 1 or 100 items. (I tested both).

链接地址: http://www.djcxy.com/p/41264.html

上一篇: 组合框SelectedItem = null与DisplayMemberPath

下一篇: ComboBox花费太长时间才能打开(COMException错误)