我有一个 WPF 应用程序,我在画布上移动数据。当我像个怪物一样尝试用鼠标移动数据时,问题就开始了。
以下是动作顺序:
- 画布上的 MouseMove 被触发
- 在 MouseMove 中,我更改了一些数据
- Trace.Assert 失败。调试器不会中断,消息框也不会中断
- 另一个 MouseMove 被触发
- 数据又变了
- 由于集合中的重入检查而引发异常。调试器在那里中断。断言消息框从未显示。
这里最大的问题是我可以回到断言,但不是断言失败时的数据,而是最后修改的数据......所以基本上我无法正确调试。
这是堆栈跟踪,从第一个 MouseMove 开始(注意 ShowMessageBoxAssert 以及它仍在继续的事实......):
.Models.FCurve.MoveKey(int keyIndex = 3, double keyTime = 1182.0) 第 199 行 C# .Models.FCurve.KeyTimeChanged(Models.FCurveKey timeChangeKey = {Models.FCurveKey}) 第 186 行 + 0x2d 字节 C# .Models.FCurve.AddKeyToArray.AnonymousMethod(object sender = {Models.FCurveKey}, System.EventArgs args = {System.EventArgs}) 第 163 行 + 0x11 字节 C# [本机到托管转换] [管理到本地转换] .Models.FCurveKey.OnTimeChanged() 第 45 行 + 0x14 字节 C# .Models.FCurveKey..ctor.AnonymousMethod(object sender = {FCurveEditorTestApp.Impl.FCurveKeyImpl}, System.EventArgs args = {System.EventArgs}) 第 18 行 + 0x8 字节 C# [本机到托管转换] [管理到本地转换] FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.OnTimeChanged() 第 43 行 + 0x14 字节 C# FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.Time.set(double value = 1182.0) Line 34 + 0x8 bytes C# .Models.FCurveKey.Time.set(double value = 1182.0) 第 36 行 + 0x1b 字节 C# .ViewModels.CurveKeyViewModel.X.set(double value = 1182.0) 第 32 行 + 0x2b 字节 C# .ViewModels.CurveAreaViewModel.MoveSelectedItem.AnonymousMethod(ViewModels.CurveKeyViewModel key = {ViewModels.CurveKeyViewModel}) 第 127 行 + 0x2d 字节 C# Collections.CollectionHelper.ForEach(System.Collections.Generic.IEnumerable source = {System.Linq.Enumerable.OfTypeIterator}, System.Action action = {Method = {Void b__8(ViewModels.CurveKeyViewModel)}}) 第 31 行 + 0xe 字节 C# .ViewModels.CurveAreaViewModel.MoveSelectedItem(double deltaX = 693.0, double deltaY = 35.0) 第 126 行 + 0x63 字节 C# .Views.CurveAreaView._AreaCanvas_MouseMove(object sender = {System.Windows.Controls.Canvas}, System.Windows.Input.MouseEventArgs e = {System.Windows.Input.MouseEventArgs}) 第 195 行 + 0x2d 字节 C# PresentationCore.dll!System.Windows.Input.MouseEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) + 0x34 bytes PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate 处理程序,对象目标) + 0x27 字节 PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,System.Windows.RoutedEventArgs routedEventArgs) + 0x3e 字节 PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(对象源 = {System.Windows.Controls.Canvas},System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseEventArgs},bool reRaised = false)+ 0x1bf 字节 PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.Canvas},System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseEventArgs})+ 0x79 字节 PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseEventArgs}, bool trust) + 0x35 字节 PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() + 0x311 字节 PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs 输入) + 0x42 字节 PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) + 0x62 字节 PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode 模式, int 时间戳, System.Windows.Input.RawMouseActions 动作, int x, int y, int wheel) + 0x2e2 字节 PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 2628604,int msg = 512,System.IntPtr wParam = 1,System.IntPtr lParam = 30409804,ref bool 处理 = false)+ 0x22b 字节 PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = 2628604,int msg = 512,System.IntPtr wParam = 1,System.IntPtr lParam = 30409804,ref bool 处理 = false)+ 0x75 字节 WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 2628604,int msg = 512,System.IntPtr wParam = 1,System.IntPtr lParam = 30409804,ref bool 处理 = false)+ 0xbe 字节 WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x7a 字节 WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate 回调 = {Method = {System.Object DispatcherCallbackOperation(System.Object)}},对象 args = {MS.Win32.HwndSubclass.DispatcherOperationCallbackParameter},bool isSingleParameter = true) + 0x8a 字节 WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate 回调, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x4a 字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate 回调,对象 args,bool isSingleParameter,System.Delegate catchHandler) + 0x44 字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority 优先级, System.TimeSpan 超时, System.Delegate 方法, 对象参数, bool isSingleParameter) + 0x91 字节 WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority 优先级,System.Delegate 方法,对象 arg) + 0x40 字节 WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 2628604, int msg = 512, System.IntPtr wParam = 1, System.IntPtr lParam = 30409804) + 0xdc 字节 [本机到托管转换] [管理到本地转换] System.dll!System.Diagnostics.AssertWrapper.ShowMessageBoxAssert(string stackTrace, string message, string detailMessage) + 0x103 字节 System.dll!System.Diagnostics.DefaultTraceListener.Fail(字符串消息,字符串detailMessage)+ 0xb2字节 System.dll!System.Diagnostics.DefaultTraceListener.Fail(字符串消息)+ 0xa 字节 System.dll!System.Diagnostics.TraceInternal.Fail(string message = "") + 0xb6 bytes System.dll!System.Diagnostics.Trace.Assert(布尔条件)+ 0x1c 字节 .ViewModels.CurvePathViewModel.CurvePathViewModel(Models.FCurveKey startKey = {Models.FCurveKey}, Models.FCurveKey endKey = {Models.FCurveKey}, ViewModels.IInterpolationProvider interpolatorProvider = {ViewModels.InterpolationInfoProvider}) 第 29 行 + 0x4e 字节 C# .ViewModels.CurvePathViewModel.CurvePathViewModel(ViewModels.CurveKeyViewModel startKey = {ViewModels.CurveKeyViewModel}, ViewModels.CurveKeyViewModel endKey = {ViewModels.CurveKeyViewModel}, ViewModels.IInterpolationProvider interpolatorProvider = {ViewModels.InterpolationInfoProvider}) 第 20 行 + 0x81 字节 C# .ViewModels.CurveViewModel.UpdateSegmentForKey(ViewModels.CurveKeyViewModel key = {ViewModels.CurveKeyViewModel}) 第 215 行 + 0x41 字节 C# .ViewModels.CurveViewModel.KeyViewModelsChanged(object sender = Count = 13, System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) 第 187 行 + 0x30 字节 C# [本机到托管转换] [管理到本地转换] WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x50 字节 WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedAction action, object item, int index, int oldIndex) + 0x34 bytes WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.MoveItem(int oldIndex, int newIndex) + 0x6f 字节 WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.Move(int oldIndex, int newIndex) + 0xe 字节 Collections.CollectionSynchronizer._SourceList_CollectionChanged(object sender = Count = 13, System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) 第 239 行 + 0x45 字节 C# [本机到托管转换] [管理到本地转换] WindowsBase.dll!System.Collections.ObjectModel.ReadOnlyObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args) + 0x1d 字节 WindowsBase.dll!System.Collections.ObjectModel.ReadOnlyObservableCollection.HandleCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0xe 字节 [本机到托管转换] [管理到本地转换] WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x50 字节 WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedAction action, object item, int index, int oldIndex) + 0x34 bytes WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.MoveItem(int oldIndex, int newIndex) + 0x6f 字节 WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.Move(int oldIndex, int newIndex) + 0xe 字节 .Models.FCurve.MoveKey(int keyIndex = 1, double keyTime = 489.0) 第 199 行 + 0x19 字节 C# .Models.FCurve.KeyTimeChanged(Models.FCurveKey timeChangeKey = {Models.FCurveKey}) 第 186 行 + 0x2d 字节 C# .Models.FCurve.AddKeyToArray.AnonymousMethod(object sender = {Models.FCurveKey}, System.EventArgs args = {System.EventArgs}) 第 163 行 + 0x11 字节 C# [本机到托管转换] [管理到本地转换] .Models.FCurveKey.OnTimeChanged() 第 45 行 + 0x14 字节 C# .Models.FCurveKey..ctor.AnonymousMethod(object sender = {FCurveEditorTestApp.Impl.FCurveKeyImpl}, System.EventArgs args = {System.EventArgs}) 第 18 行 + 0x8 字节 C# [本机到托管转换] [管理到本地转换] FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.OnTimeChanged() 第 43 行 + 0x14 字节 C# FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.Time.set(double value = 489.0) Line 34 + 0x8 bytes C# .Models.FCurveKey.Time.set(double value = 489.0) 第 36 行 + 0x1b 字节 C# .ViewModels.CurveKeyViewModel.X.set(double value = 489.0) 第 32 行 + 0x2b 字节 C# .ViewModels.CurveAreaViewModel.MoveSelectedItem.AnonymousMethod(ViewModels.CurveKeyViewModel key = {ViewModels.CurveKeyViewModel}) 第 127 行 + 0x2d 字节 C# Collections.CollectionHelper.ForEach(System.Collections.Generic.IEnumerable source = {System.Linq.Enumerable.OfTypeIterator}, System.Action action = {Method = {Void b__8(ViewModels.CurveKeyViewModel)}}) 第 31 行 + 0xe 字节 C# .ViewModels.CurveAreaViewModel.MoveSelectedItem(double deltaX = 82.0, double deltaY = -9.0) 第 126 行 + 0x63 字节 C# Views.CurveAreaView._AreaCanvas_MouseMove(object sender = {System.Windows.Controls.Canvas}, System.Windows.Input.MouseEventArgs e = {System.Windows.Input.MouseEventArgs}) 第 195 行 + 0x2d 字节 C#
问题是:为什么会发生这种情况,我应该怎么做才能让它在断言时中断?
我想过使用异常,也许是为了调试,但这确实是我需要的断言。我也在考虑我所有其他的断言,而不需要总是将它们转换为异常进行调试......