Hello, I have a WPF application that utilizes the MVVM pattern. On my view is a RadGridView defined as
Corresponding in my ViewModel I have a property
On the View Model is a timer that refreshes the data every 60 seconds
The tick event and refresh method
worker is a BackgroundWorker that allows me to load data asynchronously
Occasionally in Production users will get a NullReferenceException at some point when the grid is trying to re-draw. Here is the stack trace.
at Telerik.Windows.Controls.GridView.Automation.GridViewCellAutomationPeer.GetNameCore() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Automation\GridViewCellAutomationPeer.cs:line 146
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.Automation.Peers.AutomationPeer.UpdatePeer(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at PartsFinder.Chimera.App.Main() in d:\TeamCityWork\PARTSFinderSlnProd\Chimera\PartsFinder.Chimera\obj\x86\Prod-Warehouse\App.g.cs:line 50
This exception doesn't happen every time, in fact it is very random. But the users get annoyed when it happens several times during the day. Does anyone have any ideas?
Thanks
<
telerik:RadGridView
Name
=
"grdOrders"
Grid.Row
=
"1"
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding LineItems}"
SelectedItem
=
"{Binding Path=SelectedLineItem}"
IsSynchronizedWithCurrentItem
=
"True"
IsReadOnly
=
"True"
ClipboardCopyMode
=
"Cells"
RowStyleSelector
=
"{StaticResource backorderStyleSelector}"
ScrollViewer.HorizontalScrollBarVisibility
=
"Auto"
ScrollViewer.VerticalScrollBarVisibility
=
"Auto"
MouseDoubleClick
=
"grdOrders_MouseDoubleClick"
SelectionMode
=
"Extended"
>
<
i:Interaction.Behaviors
>
<
b:MultiSelectBehavior
SelectedItems
=
"{Binding Path=SelectedLineItems}"
/>
</
i:Interaction.Behaviors
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=GPPONumber}"
Header
=
"GP PO Number"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=LineItemId}"
Header
=
"Line Item Id"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=Quantity}"
Header
=
"Quantity"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=PartNumber}"
Header
=
"Part Number"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=Description}"
Header
=
"Description"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=WarehouseCode}"
Header
=
"Warehouse"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=WarehouseBin}"
Header
=
"Bin Location"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=ShippingMethod}"
Header
=
"Shipping Method"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=VendorName}"
Header
=
"Vendor Name"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=Salesrep}"
Header
=
"Sales Rep"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=SourcedBy}"
Header
=
"Sourced By"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=Backordered}"
Header
=
"B/O?"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
Corresponding in my ViewModel I have a property
public
ObservableCollection<WarehouseLineItemProxy> LineItems
{
get
{
return
lineItems;
}
set
{
lineItems = value;
RaisePropertyChanged(() => LineItems);
ViewOrderInfoCommand.RaiseCanExecuteChanged();
}
}
On the View Model is a timer that refreshes the data every 60 seconds
refreshTimer =
new
DispatcherTimer();
refreshTimer.Interval = TimeSpan.FromSeconds(60);
refreshTimer.Tick +=
new
EventHandler(refreshTimer_Tick);
The tick event and refresh method
/// <summary>
/// Handles the Tick event of the refreshTimer control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private
void
refreshTimer_Tick(
object
sender, EventArgs e)
{
refreshTimer.Stop();
RefreshLineItems(
new
object
());
refreshTimer.Start();
}
/// <summary>
/// Refreshes the line items.
/// </summary>
/// <param name="arg">The arg.</param>
private
void
RefreshLineItems(
object
arg)
{
if
(!worker.IsBusy)
{
ShowBusyIndicator =
true
;
worker.RunWorkerAsync();
refreshTimer.Stop();
refreshTimer.Start();
}
}
worker is a BackgroundWorker that allows me to load data asynchronously
/// <summary>
/// Handles the DoWork event of the worker control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
private
void
worker_DoWork(
object
sender, DoWorkEventArgs e)
{
e.Result = adapter.LoadWarehouseOrders();
}
/// <summary>
/// Handles the RunWorkerCompleted event of the worker control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.ComponentModel.RunWorkerCompletedEventArgs"/> instance containing the event data.</param>
private
void
worker_RunWorkerCompleted(
object
sender, RunWorkerCompletedEventArgs e)
{
Dispatcher.CurrentDispatcher.BeginInvoke(
new
Action<ObservableCollection<WarehouseLineItemProxy>>(
this
.UpdateGridData), e.Result);
}
/// <summary>
/// Updates the grid data.
/// </summary>
/// <param name="lineItems">The line items.</param>
private
void
UpdateGridData(ObservableCollection<WarehouseLineItemProxy> lineItems)
{
LineItems = lineItems;
ShowBusyIndicator =
false
;
}
Occasionally in Production users will get a NullReferenceException at some point when the grid is trying to re-draw. Here is the stack trace.
at Telerik.Windows.Controls.GridView.Automation.GridViewCellAutomationPeer.GetNameCore() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Automation\GridViewCellAutomationPeer.cs:line 146
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.Automation.Peers.AutomationPeer.UpdatePeer(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at PartsFinder.Chimera.App.Main() in d:\TeamCityWork\PARTSFinderSlnProd\Chimera\PartsFinder.Chimera\obj\x86\Prod-Warehouse\App.g.cs:line 50
This exception doesn't happen every time, in fact it is very random. But the users get annoyed when it happens several times during the day. Does anyone have any ideas?
Thanks