-
Type: Task
-
Resolution: Done
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
Goals
Process query in the background
Description
Hi guys, I have a table in the realm with 90,000 records! I wanted to query this table to put it in a listview, so far so good, but the query takes 4/5 seconds (and if filtering through some fields takes 20/30 seconds) and in that time, I get the UI blocked,
I tried inside a Task.Run, but I can't use throw the Thread error, i try user ThreadSafeReference but no success!
What is the best way to do this?
Expected Results
No UI LAG
Code Sample
private IEnumerable<Entities.Product> GetProducts() { Products = SharedClass.RealmBD.All<Entities.Product>().Where(p => p.Company.Equals(SharedClass.Session.Company)); if (!string.IsNullOrEmpty(SharedClass.Session.Warehouse)) Products = Products.Where(p => p.Warehouse.Equals(SharedClass.Session.Warehouse)); return Products; }
public class Product : RealmObject { [Indexed] public string Company { get; set; } [PrimaryKey, JsonProperty("ID")] public string ProductID { get; set; } [JsonIgnore] public Guid ID { get => new Guid(ProductID); set => ProductID = value.ToString(); } [Indexed] public string Code { get; set; } [Indexed] public string Warehouse { get; set; } public string Color { get; set; } public string Size { get; set; } public string BarCode { get; set; } [Indexed] public string Name { get; set; } }