Issue
I have an Xamarin App using Parallel.Invoke which is working fine on Android.
Parallel.Invoke
(
() => AddOrReplaceWordsAndDefinitions(wordsAndDefinitions, conn),
() => AddOrReplaceWords(wordsAndDefinitions, conn)
);
However I'm now trying to work on the iOS version and it crashes not because of the Parallel.Invoke but because of the lambda expression () =>
If I do a Parallel.Invoke with action as below it will work on iOS but I won't have my parameters:
Parallel.Invoke
(
Action1,
Action2
);
I've tried to use Tasks instead of parallel.invoke but since my code doesn't use async, I have to use the lambda expression () =>
at some point, here or somewhere else.
I've also tried to use delegate but it's not working either on iOS. So the only options I've found so far is to use System.Action instead of normal methods and store the parameters somewhere else to access in the actions. Or having two versions of the code, one with parallel.invoke for android and one without for iOS.
If you know a better option or if you know why lambda expression are not working on Xamarin iOS let me know.
For references I'm using:
- Xamarin form v4.4.0.991265
- Simulations of iPhone8 and iPhone11 pro
Solution
Ok I've found the solution:
The problem is not coming from the delegate but from the "conn" object parameter I pass through. I cannot set a connection (here a SQLite connection) and pass it through different methods run in parallel. It works on Android but not on iOS.
So I've kept the Parallel.Invoke but removed the connection parameter and I now set connection in the individual methods.
Answered By - Syl.H
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.