0
I’m taking elements from a list and I can’t erase the elements, I have to return them all. I found a problem at the end of this query, where you have the comment
//Erro
tagItems.AddElementsTo(this.TagItems);
Below is the code of the whole method to be able to analyze.
public void Initialize(System.Windows.Threading.Dispatcher dispatcher)
{
var logbookDisposable = default(IDisposable);
var tagsDisposable = default(IDisposable);
var tagValuesDisposable = default(IDisposable);
var clockDisposable = Observable.Interval(TimeSpan.FromSeconds(15))
.StartWith(-1L)
.SubscribeOn(dispatcher)
.Synchronize()
.Subscribe(_ => DateTime = DateTime.Now);
var mainDisposable = Observable.Interval(TimeSpan.FromMinutes(15))
.StartWith(-1L)
.SubscribeOn(dispatcher)
.SelectMany(async _ =>
{
this.TagItems = new ObservableCollection<TagItem>();
var subscriptions = await GetSubscriptionsAsync();
return subscriptions;
})
.SelectMany(subs => subs)
.Subscribe(sub =>
{
var info = sub.info;
var tags = sub.tags;
logbookDisposable?.Dispose();
logbookDisposable = Observable.Interval(TimeSpan.FromMinutes(15))
.StartWith(-1L)
.SubscribeOn(dispatcher)
.Synchronize()
.SelectMany(async _ => await GetLogbookItems(info))
.SubscribeOn(dispatcher)
.Synchronize()
.Subscribe(logbookItems =>
{
this.LogbookItems = logbookItems.ToObservableCollection();
});
tagsDisposable?.Dispose();
tagsDisposable = Observable.Interval(TimeSpan.FromMinutes(15))
.StartWith(-1L)
.SubscribeOn(dispatcher)
.Synchronize()
.SelectMany(async _ => await GetTagItems(tags))
.SubscribeOn(dispatcher)
.Synchronize()
.Subscribe(tagItems =>
{
//Erro
tagItems.AddElementsTo(this.TagItems);
tagValuesDisposable?.Dispose();
tagValuesDisposable = Observable.Interval(TimeSpan.FromSeconds(30))
.SelectMany(async _ => await GetTagValues((from ti in tagItems select ti.ID).ToArray()))
.SubscribeOn(dispatcher)
.Synchronize()
.Subscribe(tagValues =>
{
var query = (from ti in tagItems
join tv in tagValues on ti.ID equals tv.TagID
select new { ti, tv }).ToArray();
foreach (var item in query)
{
item.ti.Value = item.tv.Value;
}
});
});
});
var disposable = new Core.Utils.DisposeInvoker(() =>
{
clockDisposable?.Dispose();
mainDisposable?.Dispose();
logbookDisposable?.Dispose();
tagsDisposable?.Dispose();
tagValuesDisposable?.Dispose();
});
disposables.Add(disposable);
}