3

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).

Mixxiphoid
  • 1,044
  • 6
  • 26
  • 46
  • Maybe some code examples? hard to follow your thought well without seeing something – Brad Fox Apr 16 '12 at 12:10
  • 1
    It is not an exception, it is a warning. Telling you what you already know, your UI thread is dead for a minute. An "I click this then that" description of the problem isn't good enough to help us help you. You'll need to find out what's taking so long. – Hans Passant Apr 16 '12 at 12:15
  • @HansPassant I was hoping you could tell me what is happening since I cannot set a breakpoint within the ComboBox controls. I already tried to catch all errors, but nothing is throwing an error, no memory is being filled up, nothing I can think up... – Mixxiphoid Apr 16 '12 at 12:19
  • @Taeeril I Added some code but I doubt it will help. It is nothing special. – Mixxiphoid Apr 16 '12 at 12:19
  • I dont see anything wrong with way your binding data so, I agree with Hans on this one, its a matter of what is causing it to go so slow. – Brad Fox Apr 16 '12 at 12:24
  • @Taeeril that cause is exactly what I want to know, any ideas? – Mixxiphoid Apr 16 '12 at 12:51
  • @Mixxiphoid All I can think of off the top of my head is something to do with either dataset size, or slow connection to server where your getting your information – Brad Fox Apr 16 '12 at 13:21

0 Answers0