Created
March 13, 2018 05:37
-
-
Save azyobuzin/ea8785c7f3de171d4ff30a827bccb230 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
TaskScheduler.UnobservedTaskException += (sender, e) => | |
{ | |
Console.WriteLine(e.Exception.ToString()); | |
}; | |
// var task1 = Task.Run(() => throw new Exception()); | |
// var task2 = task1.ContinueWith | |
// と書くと、 task1 が GC されないので UnobservedTaskException が発生しない | |
var task = Task.Run(() => throw new Exception()) | |
.ContinueWith(t => Console.WriteLine("hoge")); | |
task.Wait(); | |
Console.WriteLine(task.Status); | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment