This is a migrated thread and some comments may be shown as answers.

InvalidOperationException When Expanding Tree Nodes.

3 Answers 154 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 02 Oct 2012, 07:51 PM

I'm using the tree control from C#.  Our application can fill the tree with a lot of data. Every time a user either expands an individual tree node or initiates the expand all nodes call, if any column is set to be sorted, an InvalidOperationException is thrown when Telerik's internal code is calling the "get" method of the "Column" property in the Telerik.Windows.Controls.GridView.ColumnSortDescriptor class.

The the VS debugger flags the exception in the file "c:\RadControlsSource\Controls\GridView\GridView\GridView\Sorting\ColumnSortDescriptor.cs", line 38.

Here's the exception information:

System.InvalidOperationException was unhandled by user code
  Message="The calling thread cannot access this object because a different thread owns it."
  Source="WindowsBase"
  StackTrace:
       at System.Windows.Threading.Dispatcher.VerifyAccess()
       at System.Windows.Threading.DispatcherObject.VerifyAccess()
       at System.Windows.DependencyObject.GetValue(DependencyProperty dp)
       at Telerik.Windows.Controls.GridView.ColumnSortDescriptor.get_Column()
       at Telerik.Windows.Controls.GridView.ColumnSortDescriptor.CreateSortKeyExpression(ParameterExpression parameterExpression)
       at Telerik.Windows.Data.SortDescriptorBase.CreateSortKeyExpression(Expression itemExpression)
       at Telerik.Windows.Data.Expressions.SortDescriptorCollectionExpressionBuilder.Sort()
       at Telerik.Windows.Data.QueryableExtensions.Sort(IQueryable source, IEnumerable`1 sortDescriptors)
       at Telerik.Windows.Data.QueryableExtensions.Sort(IQueryable source, SortDescriptorCollection sortDescriptors)
       at Telerik.Windows.Data.HierarchicalCollectionViewBase.get_BaseView()
       at Telerik.Windows.Data.HierarchicalCollectionViewBase.CreateHierachyView(HierarchicalCollectionViewBase view)
       at Telerik.Windows.Data.HierarchyItem.get_Children()
       at Telerik.Windows.Data.HierarchicalCollectionViewBase.<CreateView>b__23(HierarchyItem h)
       at Telerik.Windows.Data.EnumerableExtensions.<SelectRecursive>d__3`1.MoveNext()
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
       at Telerik.Windows.Data.HierarchicalCollectionViewBase.PopulateInternalList(IQueryable view)
       at Telerik.Windows.Data.HierarchicalCollectionViewBase.<>c__DisplayClass32.<CreateInternalList>b__2e(Object s, DoWorkEventArgs e)
       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
  InnerException:

I am accessing the TreeListView control from the main UI thread. When this exception happens, the state of the tree control is hosed and our Windows desktop application must be restarted. Can anyone give me a clue as to how I can avoid this problem?  Thanks.

3 Answers, 1 is accepted

Sort by
0
Don
Top achievements
Rank 1
answered on 02 Oct 2012, 07:57 PM
FYI - Here's how the TreeLIstView control is defined in our XAML file:

<telerik:RadTreeListView
    Name="JobTreeListView"
    AutoGenerateColumns="False"
    HierarchyColumnIndex="0"
    ItemsSource="{Binding RunningWorkflowDataModelView}"
    FontSize="10"
    Foreground="White"
    GridLinesVisibility="None"
    telerik:StyleManager.Theme="Expression_Dark"
    VerticalAlignment="Stretch"
    HorizontalAlignment="Stretch"
    Grid.Row="0"
    VirtualizingStackPanel.IsVirtualizing="True"
    VirtualizingStackPanel.VirtualizationMode="Recycling"
    CanUserSortColumns="True"
    RowHeight="18"
    IsReadOnly="True"
    RowIndicatorVisibility="Collapsed"
    RowDetailsVisibilityMode="Collapsed"
    IsFilteringAllowed="False"
    SelectionMode="Extended"
    SelectionUnit="FullRow"
    DataLoaded="JobTreeListView_DataLoaded"
    DataLoadMode="Asynchronous"
    CanUserFreezeColumns="False"
    >
 
    <telerik:RadTreeListView.Resources>
        <Style TargetType="{x:Type telerik:TreeListViewRow}">
            <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
        </Style>
 
        <DataTemplate DataType="{x:Type s:ProgressObjectRunning}">
            <StackPanel>
                <ProgressBar Margin="1" Visibility="{Binding DataModel.VisibleIfRunning}">
                    <ProgressBar.Value>
                        <Binding Path="DataModel.Progress" Mode="OneWay"/>
                    </ProgressBar.Value>
                    <ProgressBar.Foreground>
                        <Binding Path="DataModel.ProgressColor" Mode="OneWay"/>
                    </ProgressBar.Foreground>
                </ProgressBar>
                <TextBlock Text="{Binding DataModel.StatusMessage}" Visibility="{Binding DataModel.VisibleIfPaused}" />
            </StackPanel>
        </DataTemplate>
 
        <DataTemplate DataType="{x:Type s:ProgressObjectSuccess}">
            <StackPanel Orientation="Horizontal">
                <Button Margin="0,0,2,0" Style="{StaticResource StatusGreenStyle}"></Button>
                <TextBlock Text="{Binding DataModel.StatusMessage}"></TextBlock>
            </StackPanel>
        </DataTemplate>
 
        <DataTemplate DataType="{x:Type s:ProgressObjectFailed}">
            <StackPanel Orientation="Horizontal">
                <Button Margin="0,0,2,0" Style="{StaticResource StatusRedStyle}"></Button>
                <TextBlock Text="{Binding DataModel.StatusMessage}"></TextBlock>
            </StackPanel>
        </DataTemplate>
 
        <DataTemplate DataType="{x:Type s:ProgressObjectPending}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding DataModel.StatusMessage}"></TextBlock>
            </StackPanel>
        </DataTemplate>
 
        <DataTemplate DataType="{x:Type s:ProgressObjectNotExecuted}">
            <StackPanel Orientation="Horizontal">
                <Button Margin="0,0,2,0" Style="{StaticResource StatusYellowStyle}"></Button>
                <TextBlock Text="{Binding DataModel.StatusMessage}"></TextBlock>
            </StackPanel>
        </DataTemplate>
 
        <DataTemplate DataType="{x:Type s:RunningWorkflowModel}">
            <Label Content="{Binding TargetFile}"/>
        </DataTemplate>
 
        <DataTemplate DataType="{x:Type s:NewJobDataModel}">
            <Label Content="{Binding TaskType}"/>
        </DataTemplate>
 
    </telerik:RadTreeListView.Resources>
 
    <telerik:RadTreeListView.ContextMenu>
        <ContextMenu>
            <MenuItem
                Header="{l:Translate MenuItem.ExpandAllItems}"
                Command="{Binding ExpandAllItemsCommand.Command}"
                />
            <MenuItem
                Header="{l:Translate MenuItem.CollapseAllItems}"
                Command="{Binding CollapseAllItemsCommand.Command}"
                />
            <Separator />
            <MenuItem
                    x:Name="ResumeJobMenuItem"
                    Header="{l:Translate MenuItem.ResumeJob}"
                    Command="{Binding ResumeJobCommand.Command}"
                    />
            <MenuItem
                    x:Name="PauseJobMenuItem"
                    Header="{l:Translate MenuItem.PauseJob}"
                    Command="{Binding PauseJobCommand.Command}"
                    />
            <MenuItem
                    x:Name="StopJobMenuItem"
                    Header="{l:Translate MenuItem.StopJob}"
                    Command="{Binding StopJobCommand.Command}"
                    />
            <!--<MenuItem
                    x:Name="RequeueJobMenuItem"
                    Header="{l:Translate MenuItem.RequeueJob}"
                    Command="{Binding RequeueJobCommand.Command}"
                    />-->
        </ContextMenu>
    </telerik:RadTreeListView.ContextMenu>
 
    <telerik:RadTreeListView.Columns>
 
        <telerik:GridViewDataColumn
            x:Name="JobGridViewColumn"
            IsSortable="True"
            SortingState="Ascending"
            IsCustomSortingEnabled="False"
            SortMemberPath="TargetFile"
            DataMemberBinding="{Binding TargetFile}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.Job}" ToolTipService.ToolTip="{l:Translate ToolTip.JobGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="TaskNameGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding TaskName}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.TaskName}" ToolTipService.ToolTip="{l:Translate ToolTip.TaskNameGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding TaskName}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="JobProgressGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding Progress}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.JobProgress}" ToolTipService.ToolTip="{l:Translate ToolTip.JobProgressGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <ContentPresenter Margin="1" Content="{Binding ProgressObject}"/>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="TreeViewPriorityGridViewColumn"
            Width="120"
            IsResizable="True"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            SortMemberPath="PrioritySortValue"
            DataMemberBinding="{Binding Priority}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.Priority}" ToolTipService.ToolTip="{l:Translate ToolTip.TreeViewPriorityGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <em:PrioritySlider
                        x:Name="WorkflowPrioritySlider"
                        OnNewSliderValueReady="PrioritySlider_NewValueReady"
                        />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="CurrentTimeGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding CurrentTime}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.CurrentTime}" ToolTipService.ToolTip="{l:Translate ToolTip.CurrentTimeGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding CurrentTime}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="MediaDurationGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding Duration}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.MediaDuration}" ToolTipService.ToolTip="{l:Translate ToolTip.MediaDurationGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding Duration}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="PassGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding MultipassPass}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.Pass}" ToolTipService.ToolTip="{l:Translate ToolTip.PassGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding MultipassPass}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="StartTimeGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding StartTime, Converter={StaticResource dateConverter}}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.StartTime}" ToolTipService.ToolTip="{l:Translate ToolTip.StartTimeGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding StartTime, Converter={StaticResource dateConverter}}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="EndTimeGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding CompletedTime, Converter={StaticResource dateConverter}}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.EndTime}" ToolTipService.ToolTip="{l:Translate ToolTip.EndTimeGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding CompletedTime, Converter={StaticResource dateConverter}}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="AttemptGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding Attempt}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.Attempt}" ToolTipService.ToolTip="{l:Translate ToolTip.AttemptGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding Attempt}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="MachineGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding NodeName}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.Machine}" ToolTipService.ToolTip="{l:Translate ToolTip.MachineGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding NodeName}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn
            x:Name="SubmitterGridViewColumn"
            IsSortable="True"
            SortingState="None"
            IsCustomSortingEnabled="False"
            DataMemberBinding="{Binding SubmitterClient}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{l:Translate GridViewColumn.Submitter}" ToolTipService.ToolTip="{l:Translate ToolTip.SubmitterGridViewColumn}" />
            </telerik:GridViewDataColumn.Header>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding SubmitterClient}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
    </telerik:RadTreeListView.Columns>
 
    <telerik:RadTreeListView.ChildTableDefinitions>
        <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}" />
    </telerik:RadTreeListView.ChildTableDefinitions>
 
</telerik:RadTreeListView>
0
Vlad
Telerik team
answered on 03 Oct 2012, 05:30 AM
Hi,

Please remove DataLoadMode="Asynchronous" to avoid this. 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Don
Top achievements
Rank 1
answered on 03 Oct 2012, 04:37 PM
That did the trick. Thanks, Vlad! :)
Tags
TreeListView
Asked by
Don
Top achievements
Rank 1
Answers by
Don
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or