c# – 抛出Task.ThrowIfExceptional的异常是什么?

前端之家收集整理的这篇文章主要介绍了c# – 抛出Task.ThrowIfExceptional的异常是什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个使用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()

什么是真正的例外?

如果这不是提出这个问题的正确位置,请告诉我并删除它.

我不是问对象引用没有设置为对象实例的含义是什么.我知道,我问这是否是使得任务抛出System.Threading.Tasks.Task的异常. ThrowIfExceptional.

解决方法

执行返回Task的操作时会发生什么,任何异常都存储在任务的Task.Exception属性中.

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

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

MyCompany.Dispositivos.Plugins.TICAnKorr.DeviceTICAnKorr.StopLive()
原文链接:https://www.f2er.com/csharp/244883.html

猜你在找的C#相关文章