我在 ASP.NET 框架 4.0 中使用 HttpClient。所有示例都是我见过的使用 OnBeginXX/OnEndXXX 或 async/await(4.5) 和 RegisterAsyncTask。我需要询问如何使 RegisterAsyncTask 与 HtpClient 的 GetByteArrayAsync(或类似)一起工作。注意这是 ASP.NET 4.0?
更新:刚刚发现在4.5 中你有比 2.0 更多的重载,
Public method PageAsyncTask(Func<Task>) Initializes a new instance of the PageAsyncTask class using an event handler that enables the task to be handled.
Public method PageAsyncTask(Func<CancellationToken, Task>) Initializes a new instance of the PageAsyncTask class using an event handler that enables the task to be canceled.
Public method PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object) Initializes a new instance of the PageAsyncTask class using the default value for executing in parallel.
Public method PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object, Boolean) Initializes a new instance of the PageAsyncTask class using the specified value for executing in parallel.
还有其他解决方案吗?
更新 2:我认为 TPL 在 4.0 中不受推荐的 RegisterAsyncTask 支持。需要将HttpWebRequest 与 RegisterAssyncTask一起使用