2012-08-14 36 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