且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将元素添加到ObservableCollection会导致异常索引超出范围

更新时间:2023-12-03 11:30:22

问题的根源在于包含IndexOf()方法的部分.它是在主线程上的始祖执行之前执行的,索引始终为-1.通过更改来解决:

The root of problem was the part that contains IndexOf() method. It was executing before the ancedent execution on Main Thread and index was always -1. Fixed by changing:

Device.BeginInvokeOnMainThread(() => ... );

作者

await Device.InvokeOnMainThreadAsync(() => { ... } );