Hello @Team,
I'm implementing an access page. This page contains a datalist with accesses that are constantly refreshed from the database. Each access has a list of entities. Each entity has a main photo that is stored locally in the server machine.
To implement this I ended up with this algorithm inside the Load method:
- Get accesses from the database
- Do some controller requests to get the main photos
- Wait for some pre-configured time
- Execute the Load method again
Here's the needed code to understand this problem:
protected async System.Threading.Tasks.Task Load() {
[...]
accesses = await Global.Services.DatabaseService.ReadList<Global.Models.Access>("orderby=access.id DESC", $"limit={int.Parse(widget?.settings?.FirstOrDefault(x => x.property == "count")?.value ?? "0")}", "accessPoint=true", "accessEntities=true", "person=true", "personPhoto=true", "vehicle=true", "identifier=true", "group=true");
if (accesses != null)
foreach (var mainPhoto in accesses.SelectMany(x => x.accessEntities).Select(x => x.person).Where(x => x.personPhotos.Any(y => y.main)).Select(x => x.personPhotos.FirstOrDefault()))
mainPhoto.photo = await Photo.Download<Global.Models.PersonPhoto>(mainPhoto.photoId);
await Task.Delay(int.Parse(widget?.settings?.FirstOrDefault(x => x.property == "refreshRate")?.value ?? "0"));
await Load();
}
My problem is that the access data in the UI never have the photo value. If I remove the last two awaits in the method, they will be set as they should, but it won't automatically refresh.
Here's a list of things that I tried:
- Call Reload() before the Task.Delay
- Set accesses to null and then set to its old value
- Change accesses from IEnumerable<Global.Models.Access> to ObservableCollection<Global.Models.Access>
- Change Task.Delay to Thread.Sleep, ManualResetEvent or Timer
- Manually calling all the accesses setter code before the Task.Delay