I have a windows forms app developed with C# and .NET Framework 4.0 running Task.
I'm sorry to ask this question but I don't know where an exception occur. This is the stack trace:
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()
I think the exception thrown is this:
Object reference not set to an instance of an object.
at MyCompany.Dispositivos.Plugins.TICAnKorr.VisorTICAnKorrMini.MensajeEstado()
What is the real exception?
If this is not the right place to ask this question, please tell me and I delete it.
I'm not asking about what is the meaning of Object reference not set to an instance of an object.
, I know it, I'm asking if this the exception that makes the task to throw a System.Threading.Tasks.Task.ThrowIfExceptional
.
Run( () => throw new CustomException("This exception is expected!")); try { task. Wait(); } catch (AggregateException ae) { // Call the Handle method to handle the custom exception, // otherwise rethrow the exception. ae. Handle(ex => { if (ex is CustomException) { Console.
When using await, it's going to unwrap the first exception and return it, that's why we don't hit the catch (AggregateException e) line. But if we use something like the below code sample, we catch the AggregateException , note that it's not a good idea since we're blocking the running thread.
A task is an object that represents some work that should be done. The task can tell you if the work is completed and if the operation returns a result, the task gives you the result.
What happens when you execute an action returning a Task
is that any exceptions get stored in the task's Task.Exception
property.
When you call Wait
, the code waits for the task to finish and then re-throws any exceptions that have occurred inside an AggreagtedException
. So the ThrowIfExceptional
method is being called after the task has finished to raise any exceptions that have occurred.
So likely the problem is a null reference in whatever code got executed to return the task being waited on. Should be something inside:
MyCompany.Dispositivos.Plugins.TICAnKorr.DeviceTICAnKorr.StopLive()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With