2012-08-14 54 views
5

MonoTouch的advertisesAsParallel支持在其网站上使用此代码片段:AsParallel已轰然一个MonoTouch的应用

from item in items.AsParallel() 
    let result = DoExpensiveWork (item) 
    select result; 

然而,即使是微不足道的样本崩溃我的应用程序:

var items = new [] { 1, 2, 3 }; 
var twice = (
     from x in items.AsParallel() 
     select 2 * x 
    ).ToArray(); 

System.ExecutionEngineException has been thrown. Attempting to JIT compile method 'System.Linq.Parallel.QueryNodes.WrapHelper:<Wrap<code>1>m__4A<int>(System.Collections.Generic.IEnumerator</code>1<int>)' while running with --aot-only.

我知道MonoTouch不能处理虚拟泛型方法,但不是PLINQ应该工作?
我在做什么错?

MonoTouch版本是5.3.5。

也是一样Parallel.ForEach

System.AggregateException: One or more errors occured ---> System.Exception: 
Attempting to JIT compile method 'System.Threading.Tasks.Parallel:<ForEach`1>m__36<int>()' while running with --aot-only. 
See http://docs.xamarin.com/ios/about/limitations for more information. 
+0

@James:AFAIK - 只有在真实iOS设备上才可能使用的唯一模式,因为JIT被Apple禁止。 – 2012-08-14 19:02:15

+0

这可能是一个错误,在这里报告,并附上一个快速项目来重现它:http://bugzilla.xamarin.com – jonathanpeppers 2012-08-14 19:07:26

回答

4

This is a known limitation with MonoTouch and generics - 在这种情况下,是因为你使用结构。

它应该工作,如果你使用的对象,而不是:

var items = new object [] { 1, 2, 3 }; 
var twice = (
    from x in items.AsParallel() 
    select 2 * x 
).ToArray(); 

我们正在修正这些限制的工作,所以这将是很好,如果你可以与我们的样本项目,以发送错误报告看看是否有可能在一天内真正解决这个问题。

+1

感谢您的答案。我现在明白结构是应该受到责备的。 – 2012-09-04 10:39:34