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

Problems while changing the data of itemSource of ScheduleView in another thread.

2 Answers 57 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Qizhang
Top achievements
Rank 1
Qizhang asked on 12 Mar 2014, 04:24 PM
I got this error while updating the data of schedule view in another thread , not in dispatching thread. Per the exception message, the collection was changed already while it was being enumerated, in line 4625 in ScheduleViewBase.cs, which was triggered in the method OnQueryGoToNextAppointmentCanExecuted in ScheduleViewBase.

The situation is that I have to update the data in a timer , which will execute update in another thread. Could you please give some suggestion about how to fix it, or some work around? I was trapped for almost a week.

The message of the exception is attached.
Thanks a lot.

2 Answers, 1 is accepted

Sort by
0
Qizhang
Top achievements
Rank 1
answered on 12 Mar 2014, 04:27 PM
Sorry the attachment was uploaded successfully. I pasted it here as following:

A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
'ATOMS.CrewManagerApp.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Transactions.resources\v4.0_4.0.0.0_zh-Hans_b77a5c561934e089\System.Transactions.resources.dll'
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>未处理的异常</Description><AppDomain>ATOMS.CrewManagerApp.exe</AppDomain><Exception><ExceptionType>System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>集合已修改;可能无法执行枚举操作。</Message><StackTrace>   在 System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   在 System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   在 System.Collections.Generic.List`1.Enumerator.MoveNext()
   在 System.Linq.Enumerable.&amp;lt;OfTypeIterator&amp;gt;d__aa`1.MoveNext()
   在 System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   在 System.Linq.Enumerable.&amp;lt;SelectManyIterator&amp;gt;d__14`2.MoveNext()
   在 System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   在 System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
   在 Telerik.Windows.Controls.ScheduleViewBase.HasAppointmentsInRange(IDateSpan range, Boolean skipIntersectedWithTheRangeAppointments, Boolean moveForward, DateTimeInterval interval)
   在 Telerik.Windows.Controls.ScheduleViewBase.OnQueryGoToPreviousAppointmentCanExecuted(Object sender, CanExecuteRoutedEventArgs e)
   在 System.Windows.Input.CommandBinding.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
   在 System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   在 System.Windows.Input.CommandManager.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
   在 System.Windows.UIElement.OnCanExecuteThunk(Object sender, CanExecuteRoutedEventArgs e)
   在 System.Windows.Input.CanExecuteRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target)
   在 System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   在 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   在 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   在 System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   在 System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   在 System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapper(Object parameter, IInputElement target, Boolean trusted, CanExecuteRoutedEventArgs args)
   在 System.Windows.Input.RoutedCommand.CanExecuteImpl(Object parameter, IInputElement target, Boolean trusted, Boolean&amp;amp; continueRouting)
   在 System.Windows.Input.RoutedCommand.CriticalCanExecute(Object parameter, IInputElement target, Boolean trusted, Boolean&amp;amp; continueRouting)
   在 System.Windows.Input.RoutedCommand.CanExecute(Object parameter, IInputElement target)
   在 MS.Internal.Commands.CommandHelpers.CanExecuteCommandSource(ICommandSource commandSource)
   在 System.Windows.Controls.Primitives.ButtonBase.UpdateCanExecute()
   在 System.Windows.Controls.Primitives.ButtonBase.OnCanExecuteChanged(Object sender, EventArgs e)
   在 System.Windows.Input.CanExecuteChangedEventManager.HandlerSink.OnCanExecuteChanged(Object sender, EventArgs e)
   在 System.Windows.WeakEventManager.ListenerList.DeliverEvent(Listener&amp;amp; listener, Object sender, EventArgs args, Type managerType)
   在 System.Windows.WeakEventManager.ListenerList.DeliverEvent(Object sender, EventArgs args, Type managerType)
   在 System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
   在 System.Windows.Input.CommandManager.RequerySuggestedEventManager.OnRequerySuggested(Object sender, EventArgs args)
   在 System.Windows.Input.CommandManager.RaiseRequerySuggested(Object obj)
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   在 System.Windows.Threading.DispatcherOperation.InvokeImpl()
   在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   在 System.Windows.Threading.DispatcherOperation.Invoke()
   在 System.Windows.Threading.Dispatcher.ProcessQueue()
   在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp;amp; handled)
   在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp;amp; handled)
   在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   在 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   在 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp;amp; msg)
   在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   在 System.Windows.Threading.Dispatcher.Run()
   在 System.Windows.Application.RunDispatcher(Object ignore)
   在 System.Windows.Application.RunInternal(Window window)
   在 System.Windows.Application.Run(Window window)
   在 System.Windows.Application.Run()
   在 ATOMS.CrewManagerApp.App.Main() 位置 D:\working\SMRT\ATMOS\SRC\ATOMS.CrewManagerApp\obj\x86\Debug\App.g.cs:行号 0</StackTrace><ExceptionString>System.InvalidOperationException: 集合已修改;可能无法执行枚举操作。
   在 System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   在 System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   在 System.Collections.Generic.List`1.Enumerator.MoveNext()
   在 System.Linq.Enumerable.&amp;lt;OfTypeIterator&amp;gt;d__aa`1.MoveNext()
   在 System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   在 System.Linq.Enumerable.&amp;lt;SelectManyIterator&amp;gt;d__14`2.MoveNext()
   在 System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   在 System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
   在 Telerik.Windows.Controls.ScheduleViewBase.HasAppointmentsInRange(IDateSpan range, Boolean skipIntersectedWithTheRangeAppointments, Boolean moveForward, DateTimeInterval interval)
   在 Telerik.Windows.Controls.ScheduleViewBase.OnQueryGoToPreviousAppointmentCanExecuted(Object sender, CanExecuteRoutedEventArgs e)
   在 System.Windows.Input.CommandBinding.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
   在 System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   在 System.Windows.Input.CommandManager.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
   在 System.Windows.UIElement.OnCanExecuteThunk(Object sender, CanExecuteRoutedEventArgs e)
   在 System.Windows.Input.CanExecuteRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target)
   在 System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   在 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   在 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   在 System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   在 System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   在 System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapper(Object parameter, IInputElement target, Boolean trusted, CanExecuteRoutedEventArgs args)
   在 System.Windows.Input.RoutedCommand.CanExecuteImpl(Object parameter, IInputElement target, Boolean trusted, Boolean&amp;amp; continueRouting)
   在 System.Windows.Input.RoutedCommand.CriticalCanExecute(Object parameter, IInputElement target, Boolean trusted, Boolean&amp;amp; continueRouting)
   在 System.Windows.Input.RoutedCommand.CanExecute(Object parameter, IInputElement target)
   在 MS.Internal.Commands.CommandHelpers.CanExecuteCommandSource(ICommandSource commandSource)
   在 System.Windows.Controls.Primitives.ButtonBase.UpdateCanExecute()
   在 System.Windows.Controls.Primitives.ButtonBase.OnCanExecuteChanged(Object sender, EventArgs e)
   在 System.Windows.Input.CanExecuteChangedEventManager.HandlerSink.OnCanExecuteChanged(Object sender, EventArgs e)
   在 System.Windows.WeakEventManager.ListenerList.DeliverEvent(Listener&amp;amp; listener, Object sender, EventArgs args, Type managerType)
   在 System.Windows.WeakEventManager.ListenerList.DeliverEvent(Object sender, EventArgs args, Type managerType)
   在 System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
   在 System.Windows.Input.CommandManager.RequerySuggestedEventManager.OnRequerySuggested(Object sender, EventArgs args)
   在 System.Windows.Input.CommandManager.RaiseRequerySuggested(Object obj)
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   在 System.Windows.Threading.DispatcherOperation.InvokeImpl()
   在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   在 System.Windows.Threading.DispatcherOperation.Invoke()
   在 System.Windows.Threading.Dispatcher.ProcessQueue()
   在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp;amp; handled)
   在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp;amp; handled)
   在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   在 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   在 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp;amp; msg)
   在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   在 System.Windows.Threading.Dispatcher.Run()
   在 System.Windows.Application.RunDispatcher(Object ignore)
   在 System.Windows.Application.RunInternal(Window window)
   在 System.Windows.Application.Run(Window window)
   在 System.Windows.Application.Run()
   在 ATOMS.CrewManagerApp.App.Main() 
0
Konstantina
Telerik team
answered on 13 Mar 2014, 02:19 PM
Hi,

Could you please give us some more detail about your application - are you using PRISM, or any other information you find essential. Also, if you provide us with very basic and simple application which simulates your scenario and approach, it will be much easier for us to track down the source of the problem.

Looking forward to your reply.

Regards,
Konstantina
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
ScheduleView
Asked by
Qizhang
Top achievements
Rank 1
Answers by
Qizhang
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or