I have Visual Studio Professional 2013 and I am debugging an application which uses async/await extensively. But when I stop at breakpoint and open Debug/Windows/Tasks window, it always says "No tasks to display."
I've made two test, in one I can see task, in another I can't (I run program, and pause it). Or I can breakpoint at waiting fro task line.
using System;
using System.Threading;
using System.Threading.Tasks;
namespace TasksDebugWindowTest
{
class Program
{
static void Main(string[] args)
{
DoesNotWork();
}
static void Works()
{
Console.WriteLine("Starting");
var t = Task.Factory.StartNew(() =>
{
Task.Delay(100 * 1000).Wait();
Console.WriteLine("Task complete");
});
Console.WriteLine("Status: {0}", t.Status);
Thread.Sleep(500);
Console.WriteLine("Status: {0}", t.Status);
t.Wait();
Console.WriteLine("Done");
}
static void DoesNotWork()
{
Console.WriteLine("Starting");
var t = Task.Delay(100 * 1000);
t.Wait(); // **** Breakpoint here
Console.WriteLine("Task complete");
}
}
}
Can anybody explain why I can see tasks in one case but not in another?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…