In my program i have one page with viewmodel. Viewmodel executes Update function every 10 sec in another thread with a Timer:
// in viewmodel ctor
var timer = new Timer(Update, 0, 10000);
public ObservableCollection<Tick> Data { get; set; }
public void Update(object state)
{
var query = xbtceService.GetAllTicksAsync(); // get data from service
query.Wait();
var data = query.Result;
if (data.Any())
{
dataAccess.SaveItems(data); //save data in database
}
Data.Clear(); // ERROR, another thread
var list = dataAccess.LoadList();
foreach (var item in list)
{
Data.Add(item);
}
}
Also viewmodel have ObservableCollection
that Binded to a ListView
. How to fill ObservableCollection
from another thread with new data every 10 sec?