单声道任务尚未完成

时间:2013-05-26 21:09:49

标签: c# mono task-parallel-library monodevelop async-await

使用Task,await或Task.WhenAll始终返回System.InvalidOperationException任务尚未完成

我在Windows中测试了相同的应用程序,并且运行正常。

我发现的另一个问题是“使用时无法返回空白”:

Task<T> exampleTask = Task<T>(()=> { code; }); 

但在Windows中使用.Net Framework不会发生

我在安装了Mono 3的Ubuntu 12和OpenSuse 12以及.Net Framework 4.5作为构建目标进行了测试。

Windows中的相同代码运行。

守则

public async Task<ViewResult> Rss()
{
    var client = new HttpClient();
    var step1 = await client.GetStringAsync("https://github.com/mono/mono/commits/master.atom");
    var step2 = await client.GetStringAsync("https://aspnetwebstack.codeplex.com/project/feeds/rss");
    var step3 = await client.GetStringAsync("https://orchard.codeplex.com/project/feeds/rss");

    ViewBag.MonoActivity = GetItems(step1);
    ViewBag.MVC4Activity= GetItems(step2);
    ViewBag.OrchardActivity= GetItems(step3);

    return View();
}
public IList<SyndicationItem> GetItems(String xml)
{
    var textReader = new StringReader(xml);
    var xmlReader = XmlReader.Create(textReader);
    var feed = SyndicationFeed.Load(xmlReader);
    return feed == null ? null : new List<SyndicationItem>(feed.Items);
}

堆栈跟踪

System.InvalidOperationException
The task has not finished yet

Description: HTTP 500.Error processing request.

Details: Non-web exception. Exception origin (name of application or object): mscorlib.
Exception stack trace:
  

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()   [0x0000b] in   /home/abuild/rpmbuild/BUILD/mono-3.0.4/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62   在System.Runtime.CompilerServices.TaskAwaiter.GetResult()[0x00021]   在   /home/abuild/rpmbuild/BUILD/mono-3.0.4/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter.cs:57 at(wrapper dynamic-method)object.lambda_method   (System.Runtime.CompilerServices.Closure,System.Threading.Tasks.Task)    在   System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted   (System.Threading.Tasks.Task)at   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute   (System.IAsyncResult)at   System.Web.Mvc.Async.AsyncControllerActionInvoker /&LT;&GT; C_ DisplayClass21.b _20   (System.IAsyncResult)at   System.Web.Mvc.Async.AsyncResultWrapper / WrappedAsyncResult`1.End   ()&lt; 0x00103&gt;在   System.Web.Mvc.Async.AsyncResultWrapper.End   (System.IAsyncResult,object)&lt; 0x00073&gt;在   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod   (System.IAsyncResult)at   System.Web.Mvc.Async.AsyncControllerActionInvoker /&LT;&GT; C_ DisplayClass19 /&LT;&以及c _DisplayClass1b.b_ 15   () 在   System.Web.Mvc.Async.AsyncControllerActionInvoker /&LT;&以及c _DisplayClass31.b__2b   ()

0 个答案:

没有答案