3

これが私の問題の状況です: type の 2 つのアイテム
を持っています。コレクションを持っています。 同じウィンドウの別の場所に、ItemsSource として選択された列があります。ListBoxMyClass
MyClassList<Column>
ComboBoxMyClass.ColumnCollection

ここから問題が始まります:
ComboBox のポップアップを初めて開くと、すべてうまくいきます。
ListBox で他の項目を選択すると (および ComboBox ソースも変更すると)、ポップアップを開くのに 10 秒以上かかります。60 秒以上かかる場合は、次のエラーが表示されます。

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.

私はエラーをグーグルで検索しましたが、どこに行っても ContextSwitchDeadlocks のスローを無効にするようにというアドバイスがありましたが、これはまったく解決策ではありません!

これをさらに調べたところ、次の COMException が見つかりました。

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

スレッド/タスクなどは使用せず、ComboBox.
別のアイテムの選択時に ItemsSource を更新しようとしましたが、既に正しく設定されているため、違いはありませんでした。

このエラーについてグーグルで検索しようとしましたが、この問題の解決策はないようです。
Microsoft はこれに対する修正プログラムを提供しましたが、ダウンロードはありません。

リストボックスのコード:

    <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" />

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 イベント:

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

質問:
COMException を防ぐ方法を知っている人はいますか?

更新 1:
いくつかの Xaml コード サンプルを追加しました

更新 2:
質問を簡略化

更新 3:
本当のエラーは COM 例外であることがわかりました。
新しい情報で私の質問を更新しました。

更新 4:
ListBox 内のすべてのオブジェクトが完了し、メモリ内に存在するため、クエリは実行されません。さらに、comboBox が 1 つまたは 100 個の項目で満たされている場合でも、待機時間は常に発生します。(私は両方をテストしました)。

4

0 に答える 0