Hello,
I am developing a WPF application that uses Microsoft.SqlServerCe.Client.3.5. and LINQ
I use a grid view to show data and its XAML code looks like the following
<telerik:RadGridView x:Name="unsavedFormsGridView"
Height="300"
AutoGenerateColumns="False"
ShowGroupPanel="False"
MultipleSelect="False"
ColumnsWidthMode="Fill">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Targa"
HeaderTextAlignment="Center"
Width="70"
IsReadOnly="True"
IsFilterable="False"
IsSortable="False"
DataMemberBinding="{Binding LandfillVehiclePlate}"/>
<telerik:GridViewDataColumn Header="N° formulario"
HeaderTextAlignment="Center"
Width="110"
IsReadOnly="True"
IsFilterable="False"
IsSortable="False"
DataMemberBinding="{Binding PrintedFormCode}"/>
<telerik:GridViewDataColumn x:Name="columnSave"
IsFilterable="False"
IsSortable="False">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<Button x:Name="buttonSave" Click="buttonSave_Click">
<Image Source="/Images/CheckMark.png" Height="20" Width="20" />
<Button.ToolTip>
<StackPanel Orientation="Horizontal">
<Image Source="/Images/CheckMark.png" Height="20" Width="20" />
<Label Content="Salva in modo definitivo il formulario"/>
</StackPanel>
</Button.ToolTip>
</Button>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn x:Name="columnDelete" IsFilterable="False" IsSortable="False" >
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<Button x:Name="buttonCancel" Click="buttonCancel_Click">
<Image Source="/Images/Cancel.png" Height="20" Width="20" />
<Button.ToolTip>
<StackPanel Orientation="Horizontal">
<Image Source="/Images/Cancel.png" Height="20" Width="20" />
<Label Content="Elimina in modo definitivo il formulario"/>
</StackPanel>
</Button.ToolTip>
</Button>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
To bind data to the GridView I use an observable collection of a LINQ table get from the data context created on my SDF file.
ObservableCollection<MyTable> tempOperations = new ObservableCollection<MyTable>();
To initialize the GridView at program start I use this code
unsavedFormsGridView.ItemsSource = null;
tempOperations.Clear();
var temporaryOperations = from lto in dc.MyTable select lto;
foreach (MyTable item in temporaryOperations)
{
tempOperations.Add(item);
}
unsavedFormsGridView.ItemsSource = tempOperations;
Everything works fine and I can appreciate all data from the file into the GridView.
Very strange is the thing that happens lately, during a save process in which I write a new record that user input.
This process is started by a Button, different from those included in the gridview.
I create a new record and add it into the observable collection tempOperations in a code like this
private void buttonSaveTemporarly_Click(object sender, RoutedEventArgs e)
{
//Create the new record into currentOperation
BuildCurrentOperation();
dc.LandfillTempOperations.InsertOnSubmit(currentOperation);
dc.SubmitChanges();
unsavedFormsGridView.ItemsSource = null;
tempOperations.Add(currentOperation);
unsavedFormsGridView.ItemsSource = tempOperations;
//Set all the input controls to blank for the next new record
TempInitForm();
}
When the function terminates his job, the application does not respond to any input and more or less after 60 seconds appears the message
ContextSwitchDeadlock was detected
The CLR has been unable to transition from COM context 0x1fe3b0 to COM context 0x1fe520 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 must say that trying to understand more about this I have executed the application step by step.
At the end of the function VisualStudio 2008 asks to show a disassembly and in the address combobox of the disassembly window appears the following address
Telerik.Windows.Controls.GridView.BaseVirtualizingPanel.MeasureOverride(System.Windows.Size).
At this point my suspect is that there is something illegal I do in using GridView.
May anyone help me?
Thank you in advance
Nick