1

AsyncManager.Parameters["headlines"] = value;正在分配标题值。但是在调用 Method headlines时变为 null 。NewsCompleted

public void NewsAsync(string city)
    {
        AsyncManager.OutstandingOperations.Increment();
        NewsService newsService = new NewsService();
        newsService.GetHeadlinesCompleted += (value) =>
        {
            AsyncManager.Parameters["headlines"] = value;
            AsyncManager.OutstandingOperations.Decrement();
        };
        newsService.GetHeadlinesAsync(city);
    }

    public ActionResult NewsCompleted(string[] headlines)
    {
        return View("News", new ViewStringModel
        {
            NewsHeadlines = headlines
        });
    }

1.)我该如何调试这个?

2.)当OutstandingOperations计数变为0时,框架通过从线程池请求新线程来调用我的actionCompleted方法。当这个 actionCompleted 方法被调用时,我查看了调用堆栈并且不知道背后到底发生了什么。我的意思是框架如何知道它应该使用这个参数调用这个特定的 actionCompleted 方法AsyncManager

谢谢您的帮助。

4

1 回答 1

1

试试这些调整..

public void NewsAsync(string city)
{
    AsyncManager.OutstandingOperations.Increment();
    NewsService newsService = new NewsService();
    newsService.GetHeadlinesCompleted += (sender, args) =>
    {
        AsyncManager.Parameters["headlines"] = args.Result;
        AsyncManager.OutstandingOperations.Decrement();
    };
    newsService.GetHeadlinesAsync(city);
}

public ActionResult NewsCompleted(object headlines)
{
    return View("News", new ViewStringModel
    {
        NewsHeadlines = (string[])headlines
    });
}
于 2013-07-27T07:17:14.183 回答