Task、await、または Task.WhenAll を使用すると、常に System.InvalidOperationException が返されます。タスクはまだ終了していません。
Windows で同じアプリケーションをテストしたところ、すべて正常に動作しました。
私が見つけた別の問題は、使用したときに「voidを返せない」ことです。
Task<T> exampleTask = Task<T>(()=> { code; });
しかし、.Net Framework を使用する Windows では発生しません。
Mono 3 をインストールし、.Net Framework 4.5 をビルド対象として、Ubuntu 12 と OpenSuse 12 でテストしました。
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:
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] で /home/abuild/rpmbuild/BUILD/mono-3.0.4/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62 でシステム.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00021] in /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) で System.Web.Mvc.Async System.Web.Mvc.Async.AsyncControllerActionInvoker/<>c_DisplayClass21.b の .TaskAsyncActionDescriptor.EndExecute (System.IAsyncResult )_20 (System.IAsyncResult) at System.Web.Mvc.Async.AsyncResultWrapper/WrappedAsyncResult`1.End () <0x00103> at System.Web.Mvc.Async.AsyncResultWrapper.End (System.IAsyncResult,object) <0x00073> at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod (System.IAsyncResult) System.Web.Mvc.Async.AsyncControllerActionInvoker/<>c_ DisplayClass19 /<>c _DisplayClass1b.b_ 15 () で System.Web.Mvc.Async. AsyncControllerActionInvoker/<>c _DisplayClass31.b__2b ()