C# 将WPF应用迁移到dotnet Core 3后获取TaskCancelledException
将WPF应用程序迁移到dotnet core 3后,每当应用程序关闭时,Visual Studio调试器中都会出现TaskCancelledException 使用.NetFramework时未看到此行为 该应用程序遵循MVVM模式并执行一些异步CRUD操作,是否有可能看到问题所在,或者如何看到哪个任务返回此异常 我正在使用C# 将WPF应用迁移到dotnet Core 3后获取TaskCancelledException,c#,wpf,exception,.net-core,C#,Wpf,Exception,.net Core,将WPF应用程序迁移到dotnet core 3后,每当应用程序关闭时,Visual Studio调试器中都会出现TaskCancelledException 使用.NetFramework时未看到此行为 该应用程序遵循MVVM模式并执行一些异步CRUD操作,是否有可能看到问题所在,或者如何看到哪个任务返回此异常 我正在使用Application.Current.Shutdown()关闭应用程序如果需要任何帮助 执行异步CRUD的方法没有使用任何CancellationToken 我知道我应该分
Application.Current.Shutdown()关闭应用程序代码>如果需要任何帮助
执行异步CRUD的方法没有使用任何CancellationToken
我知道我应该分享一些代码,但我不知道从哪里开始
以下是堆栈:
System.Threading.Tasks.TaskCanceledException
HResult=0x8013153B
Message=A task was canceled.
Source=System.Private.CoreLib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at System.Windows.Threading.DispatcherOperation.Wait(TimeSpan timeout)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherOperation operation, CancellationToken cancellationToken, TimeSpan timeout)
at System.Windows.Threading.Dispatcher.Invoke[TResult](Func`1 callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout)
at System.Windows.Threading.Dispatcher.Invoke[TResult](Func`1 callback)
at Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.Properties.PropertyService.GetPropertyValuesChainInternal(Int64 instanceHandle, Object targetObject)
at Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.Properties.PropertyService.HandlePropertyChainRequest(PropertiesRequestInfo requestInfo)
at Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.HandleMessage[TMessage,TReply](Func`2 callback, Message request)
at Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.<>c__DisplayClass27_0`2.<RegisterMessageObserver>b__0(Message message)
at Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.ProcessInboundMessage(Message message)
at Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.<>c__DisplayClass40_0.<OnMessageReceived>b__0()
at Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.WaitableActionsList.<>c__DisplayClass8_0.<AddAndSignal>b__0(Boolean isCancelled)
at Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.ActionThread(Object list)
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)
System.Threading.Tasks.TaskCanceledException
HResult=0x8013153B
消息=任务已取消。
Source=System.Private.CoreLib
堆栈跟踪:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter.GetResult()中
位于System.Windows.Threading.DispatcherOperation.Wait(TimeSpan超时)
在System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherOperation操作,CancellationToken CancellationToken,TimeSpan超时)
在System.Windows.Threading.Dispatcher.Invoke[TResult](Func`1回调,DispatcherPriority,CancellationToken CancellationToken,TimeSpan超时)
在System.Windows.Threading.Dispatcher.Invoke[TResult](Func`1回调)
在Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.Properties.PropertyService.GetPropertyValuesChaininInternal(Int64 instanceHandle,Object targetObject)
在Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.Properties.PropertyService.HandlePropertyChainRequest(PropertiesRequestInfo请求信息)中
在Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.HandleMessage[TMessage,TReply](函数'2回调,消息请求)
在Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.c__DisplayClass27_0`2.b__0(消息)
位于Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.ProcessInboundMessage(消息消息消息)
位于Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.c__DisplayClass40_0.b__0()
在Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.WaitableActionsList.c__DisplayClass8_0.b__0(布尔值已取消)
位于Microsoft.VisualStudio.DesignTools.WpfTap.Networking.ProtocolHandler.ActionThread(对象列表)
位于System.Threading.ThreadHelper.ThreadStart\u上下文(对象状态)
位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext,ContextCallback回调,对象状态)
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext,ContextCallback回调,对象状态)
位于System.Threading.ThreadHelper.ThreadStart(对象obj)
根据,它“基本上是一种Visual Studio调试器功能”。因此,正如@Kevin Gosse所说,“它应该只在调试模式下发生”:“要验证这一点,请尝试禁用调试工具,方法是转到工具->选项->调试并取消选中Enable UI debugging tools for XAML”因为您使用的是WPF,所以可以尝试改用Dispatcher的功能。鉴于调用堆栈,我怀疑异常是由VisualStudio注入的线程引发的,以帮助调试WPF应用程序(在这种情况下,它应该只在调试模式下发生)。要验证这一点,请尝试禁用调试工具,方法是转到tools->Options->debug
,然后取消选中Enable UI debug tools for XAML
@kevingoss这解决了问题,如果您创建了答案,我会将其标记为已接受。