gpt4 book ai didi

c# - 引发 Task.ThrowIfExceptional 的异常是什么?

转载 作者:太空狗 更新时间:2023-10-29 20:20:06 25 4
gpt4 key购买 nike

我有一个使用 C# 和 .NET Framework 4.0 运行任务开发的 Windows 窗体应用程序。

很抱歉问这个问题,但我不知道异常发生在哪里。这是堆栈跟踪:

One or more errors occurred.
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at MyCompany.Dispositivos.Plugins.TICAnKorr.DeviceTICAnKorr.StopLive()
at MyCompany.Dispositivos.Plugins.TICAnKorr.VisorTICAnKorrMini.StopRemote()
at MyCompany.Dispositivos.InterfazDispositivos.ICBaseVisor.DesasociarDispositivo()
at MyCompany.Dispositivos.InterfazDispositivos.ControlMosaico.DesasociarTodosLosPaneles()
at MyCompany.Dispositivos.InterfazDispositivos.ControlMosaico.CrearControlSeleccionado(DeviceBase device)
at MyCompany.Dispositivos.InterfazDispositivos.ControlMosaico.icPanelViewer_MouseDown(Object sender, MouseEventArgs e)
at System.Windows.Forms.Control.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.UserControl.OnMouseDown(MouseEventArgs e)
at MyCompany.Dispositivos.InterfazDispositivos.VisorDeMosaico.mousedown(Object sender, MouseEventArgs e)
at System.Windows.Forms.Control.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.UserControl.OnMouseDown(MouseEventArgs e)
at MyCompany.BasicInterface.Controles_Basicos.ICLabel.lblText_MouseDown(Object sender, MouseEventArgs e)
at System.Windows.Forms.Control.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Label.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Object reference not set to an instance of an object.
at MyCompany.Dispositivos.Plugins.TICAnKorr.VisorTICAnKorrMini.MensajeEstado()
at MyCompany.Dispositivos.Plugins.TICAnKorr.VisorTICAnKorrMini.m_DispositivoAsociado_NewResult(Object sender)
at MyCompany.Dispositivos.ConexionesDispositivos.NewResultsEventHandler.Invoke(Object sender)
at MyCompany.Dispositivos.ConexionesDispositivos.DeviceBase.OnNewResult()
at MyCompany.Dispositivos.Plugins.TICAnKorr.DeviceTICAnKorr.HiloCaptura()
at MyCompany.Dispositivos.ConexionesDispositivos.DeviceBase.<StartLive>b__9()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()

我认为抛出的异常是这样的:

Object reference not set to an instance of an object.
at MyCompany.Dispositivos.Plugins.TICAnKorr.VisorTICAnKorrMini.MensajeEstado()

真正的异常(exception)是什么?

如果这里不适合问这个问题,请告诉我,我会删除它。

我不是在问 Object reference not set to an instance of an object. 是什么意思,我知道,我是在问这是否是导致任务执行的异常抛出 System.Threading.Tasks.Task.ThrowIfExceptional

最佳答案

当您执行返回 Task 的操作时,会发生什么异常情况会存储在任务的 Task.Exception 属性中。

当您调用 Wait 时,代码会等待任务完成,然后重新抛出 AggreagtedException 中发生的所有异常。因此,在任务完成后调用 ThrowIfExceptional 方法以引发任何已发生的异常。

很可能问题是执行任何代码以返回正在等待的任务的空引用。应该是里面的东西:

 MyCompany.Dispositivos.Plugins.TICAnKorr.DeviceTICAnKorr.StopLive()

关于c# - 引发 Task.ThrowIfExceptional 的异常是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32498666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com