Thursday, 3 October 2013

InvokeOnMainThread doesn't work with `method group`

InvokeOnMainThread doesn't work with `method group`

NOTE: I found a workaround to my problem even before asking the question,
but I'm still wondering why it behave like this.
I'm doing an usual xamarin.iOS application, using async/await, Mvvm, ...
nothing fancy on the technology side.
I found out that the following code (using a method group) wasn't working:
ViewModel.PropertyChanged += (sender, e) => {
if (e.PropertyName != "MyProperty")
return;
InvokeOnMainThread (tableViewController.TableView.ReloadData);
};
If I put a breakpoint on InvokeOnMainThread, I can see the exception:

But the same code with a lambda expression works just fine.
ViewModel.PropertyChanged += (sender, e) => {
if (e.PropertyName != "MyProperty")
return;
InvokeOnMainThread (() => tableViewController.TableView.ReloadData ());
};
A part of me is suspecting a bug, another part is already blaming my
ignorance. Anyone knows which part is right ?
Version details:
Xamarin Studio
Version 4.1.12 (build 6)
Installation UUID: [...]
Runtime:
Mono 3.2.3 ((no/8d3b4b7)
GTK+ 2.24.20 theme: Raleigh
GTK# (2.12.0.0)
Package version: 302030000
Apple Developer Tools
Xcode 5.0 (3332.22)
Build 5A1412
Xamarin.iOS
Version: 7.0.1.4 (Business Edition)
Hash: [...]
Branch:
Build date: 2013-20-09 23:14:32-0400
Build Information
Release ID: 401120006
Git revision: a9ae69a4bf37955e4ab4df0cec7804f574c51f72
Build date: 2013-09-25 16:59:37+0000
Xamarin addins: 761ae26f220068dda0b62f0dd2253f617589a8c6
Operating System
Mac OS X 10.8.5
Darwin Stephanes-MacBook-Air.local 12.5.0 Darwin Kernel Version 12.5.0
Mon Jul 29 16:33:49 PDT 2013
root:xnu-2050.48.11~1/RELEASE_X86_64 x86_64

No comments:

Post a Comment