public async Task<ActionResult> Index(string city)
But using VS 11 Dev Preview I didn't have luck using these async features. In webforms in Page_Load setting Literal controls Text property has no effect. Same happens in MVC 4 for Dev Preview 11, when setting ViewBag.Message in async
action method, that is not reflected in the output. These scenarious work fine in non-async versions though.
Thanks, that did a thing for MVC, though I still couldn't find what's wrong with WebForms. Any help on WebForms async version of Page_Load is appreciated!
For WebForms, look at http://forums.asp.net/t/1722876.aspx for an example. Note: the Page_Load event is itself
synchronous, and you call RegisterAsyncTask to tell ASP.NET that it should invoke the asynchronous callback at the appropriate time. The asynchronous callback you pass to RegisterAsyncTask is invoked immediately after PreRender.
mdonatas
Member
3 Points
4 Posts
Does async Page_Load work in asp.net 4.5 dev preview?
Oct 10, 2011 05:26 PM|LINK
Hello,
In Async CTP preview there is sample called: (C# Anders) RSS Aggregator
And News.aspx.cs has this line:
Or here http://www.asp.net/learn/whitepapers/mvc4-release-notes#_Toc303253813 MVC4 example show how to use async controllers:
But using VS 11 Dev Preview I didn't have luck using these async features. In webforms in Page_Load setting Literal controls Text property has no effect. Same happens in MVC 4 for Dev Preview 11, when setting ViewBag.Message in async action method, that is not reflected in the output. These scenarious work fine in non-async versions though.
Does anyone know why?
xinqiu
Member
476 Points
116 Posts
Microsoft
Re: Does async Page_Load work in asp.net 4.5 dev preview?
Oct 11, 2011 08:18 PM|LINK
This sample MVC4 aysnc should work, such as:
public class HomeController : AsyncController
{
[AsyncTimeout(2500)]
public async Task<ActionResult> Index()
{
WebClient wc = new WebClient();
var result = await wc.DownloadStringTaskAsync("http://aspnet.codeplex.com/project/feeds/rss");
ViewBag.Message = "test: " + result;
return View();
}
For unit test:
change
ViewResult result = controller.Index() as ViewResult;
to
ViewResult result = controller.Index().GetAwaiter().GetResult() as ViewResult;
Xinyang Qiu, Azure Web Platform and Tools team, Microsoft
mdonatas
Member
3 Points
4 Posts
Re: Does async Page_Load work in asp.net 4.5 dev preview?
Oct 16, 2011 02:15 PM|LINK
Thanks, that did a thing for MVC, though I still couldn't find what's wrong with WebForms. Any help on WebForms async version of Page_Load is appreciated!
levib
Star
7702 Points
1099 Posts
Microsoft
Re: Does async Page_Load work in asp.net 4.5 dev preview?
Oct 17, 2011 07:47 AM|LINK
For WebForms, look at http://forums.asp.net/t/1722876.aspx for an example. Note: the Page_Load event is itself synchronous, and you call RegisterAsyncTask to tell ASP.NET that it should invoke the asynchronous callback at the appropriate time. The asynchronous callback you pass to RegisterAsyncTask is invoked immediately after PreRender.