我正在进行这个简单的异步调用。我想跟踪到DownloadDataTaskAsync
方法并逐步进入Microsoft .NET框架源代码。
using System;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace WhereIsTheTaskSchedulerHere
{
class Program
{
static void Main(string[] args)
{
var task = GetData("http://sathyaish.net");
var buffer = task.Result;
var data = Encoding.ASCII.GetString(buffer);
Console.WriteLine(data);
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
async static Task<byte[]> GetData(string url)
{
var client = new WebClient();
var data = await client.DownloadDataTaskAsync(url);
return data;
}
}
}
我在 Reflector 中跟踪代码,直到代码调用了 System.Net.WebClient.DownloadBits 方法。如果该调用意味着要异步执行,则该方法通过调用 System.Net.WebRequest 类上的异步编程模型 (APM) 方法 BeginGetResponse 进一步在线程池线程上安排工作。这是 Reflector 中 DownloadBits 方法的代码。
private byte[] DownloadBits(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp)
{
WebResponse response = null;
DownloadBitsState state = new DownloadBitsState(request, writeStream, completionDelegate, asyncOp, this.m_Progress, this);
if (state.Async)
{
request.BeginGetResponse(new AsyncCallback(WebClient.DownloadBitsResponseCallback), state);
return null;
}
response = this.m_WebResponse = this.GetWebResponse(request);
int bytesRetrieved = state.SetResponse(response);
while (!state.RetrieveBytes(ref bytesRetrieved))
{
}
state.Close();
return state.InnerBuffer;
}
所以,我在Visual Studio中设置了两个断点:
1)一个在Sytem.Net.WebClient.DownloadBits
方法上;另一个在
2) 关于System.Net.WebRequest.BeginGetResponse
方法。
1)我正确配置了“Visual Studio工具->选项”对话框中的“调试”设置,允许调试器步入.NET框架源代码。
2) 我已经启用了将调试符号下载和缓存到正确位置的功能。
3)我仔细检查了位置,并发现我的代码引用的所有程序集以及特别是 System.dll
都具有调试符号,这些符号包含我设置断点的方法。
System.dll
的调试符号。所以,我点击了“加载”按钮,让它从Microsoft符号服务器在运行时下载它们。
即使如此,在它断在DownloadBits
方法时,我从调用堆栈窗口和从它打印在输出窗口中的消息中看到,它并没有显示或步入该方法的源代码。
我在 调用堆栈窗口 中右键单击 DownloadBits
方法的堆栈帧,想要点击 加载符号 菜单项,但它并不存在。因此,转到源代码 菜单项也被禁用了。
我清除了缓存并让它重新下载所有程序集,但这也没有帮助。
我正在使用Visual Studio Community Edition 2015,我的程序针对.NET框架的v4.5.2版本,并且我以前已经多次使用此设置进入过.NET源代码程序集。
我错过了什么?
System.dll
的调试符号。然而,它仍然无法进入源代码。 - Water Cooler v2System.dll
的版本也是4.6.1075.xxxx。但是,它被加载的路径是C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll。这有关系吗? - Water Cooler v2