久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

通過等待任務或訪問其異常屬性未觀察到任務的

A Task#39;s exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was(通過等待任務或訪問其異常屬性未觀察到任務的異常.結果,未觀察到
本文介紹了通過等待任務或訪問其異常屬性未觀察到任務的異常.結果,未觀察到的異常是的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

這是什么意思以及如何解決?

我正在使用 TPL 任務.

整個錯誤

<塊引用>

在等待任務或訪問其異常屬性時未觀察到任務的異常.結果,未觀察到的異常被終結器線程重新拋出.

在 System.Threading.Tasks.TaskExceptionHolder.Finalize()

mscorlib

解決方案

如果你創建了一個任務,并且你沒有調用 task.Wait() 或者嘗試檢索一個任務的結果Task<T>,當垃圾收集器收集到任務時,它會在終結期間關閉你的應用程序.有關詳細信息,請參閱 TPL 中的異常處理 上的 MSDN 頁面..p>

這里最好的選擇是處理"異常.這可以通過延續來完成 - 您可以將延續附加到任務,并記錄/吞下/等發生的異常.這提供了一種干凈的方式來記錄任務異常,并且可以寫成一個簡單的擴展方法,即:

public static void LogExceptions(this Task task){task.ContinueWith(t =>{var aggException = t.Exception.Flatten();foreach(aggException.InnerExceptions 中的 var 異常)日志異常(異常);},TaskContinuationOptions.OnlyOnFaulted);}

通過上述方法,您可以防止任何任務通過以下方式關閉應用程序并記錄它:

Task.Factory.StartNew(() =>{//做你的工作...}).LogExceptions();

或者,您可以訂閱 TaskScheduler.UnobservedTaskException 并在那里處理它.

What does this mean and how to resolve it?

I am using TPL tasks.

The whole error

A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.

at System.Threading.Tasks.TaskExceptionHolder.Finalize()

mscorlib

解決方案

If you create a Task, and you don't ever call task.Wait() or try to retrieve the result of a Task<T>, when the task is collected by the garbage collector, it will tear down your application during finalization. For details, see MSDN's page on Exception Handling in the TPL.

The best option here is to "handle" the exception. This can be done via a continuation - you can attach a continuation to the task, and log/swallow/etc the exception that occurs. This provides a clean way to log task exceptions, and can be written as a simple extension method, ie:

public static void LogExceptions(this Task task)
{
    task.ContinueWith( t =>
    {
         var aggException = t.Exception.Flatten();
         foreach(var exception in aggException.InnerExceptions)
             LogException(exception);
    }, 
    TaskContinuationOptions.OnlyOnFaulted);
}

With the above, you can prevent any task from tearing down the app, and logging it, via:

Task.Factory.StartNew( () => 
   { 
       // Do your work...
   }).LogExceptions();

Alternatively, you can subscribe to the TaskScheduler.UnobservedTaskException and handle it there.

這篇關于通過等待任務或訪問其異常屬性未觀察到任務的異常.結果,未觀察到的異常是的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a C# library that will perform the Excel NORMINV function?(是否有執行 Excel NORMINV 函數的 C# 庫?)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權列表中選擇 x 個隨機元素(無需替換))
Create a summary description of a schedule given a list of shifts(給定輪班列表,創建時間表的摘要描述)
C# Normal Random Number(C# 普通隨機數)
Standard deviation of generic list?(通用列表的標準偏差?)
AsyncCTP: Creating a class that is IAwaitable(AsyncCTP:創建一個 IAwaitable 的類)
主站蜘蛛池模板: 激情 亚洲 | 人人种亚洲 | 麻豆一区二区三区精品视频 | 欧美视频一区二区三区 | 久久99精品视频 | 久久精品国产一区二区电影 | 国产乱码精品一区二三赶尸艳谈 | 欧美一区二区在线观看 | 日韩播放 | 99热精品国产 | 日韩乱码一二三 | 日韩中出 | 成人三级视频在线观看 | 中文字幕第一页在线 | 日韩电影在线 | 精品在线一区二区三区 | 澳门永久av免费网站 | 成人在线观看免费 | 一级片在线免费播放 | 午夜精品 | 久久精品在线免费视频 | 婷婷免费视频 | 日本精品久久 | 国产特级毛片 | av天天看 | 成人在线观看网址 | 国内精品视频在线观看 | 97国产精品视频人人做人人爱 | 久久久av中文字幕 | 国产一级淫片a直接免费看 免费a网站 | a视频在线观看 | 中文精品视频 | 久久久国产精品一区 | 国产欧美一区二区三区国产幕精品 | 久草青青| 国产在线精品一区二区三区 | 欧美一区二区三区一在线观看 | 亚洲国产成人精品女人久久久 | 亚洲国产成人精品在线 | 欧美成人a| 啪啪免费网站 |