Updating a ListView from a Service Every 5 seconds
-
Good Day All i have a ListView that is defined in a Xamarin Form. i want this ListView to be updated with the Data from the DB every 5 seconds. In a Non Mobile environment , we have a Windows Service , which is a long running Service. but now i search i came across a Service. but now i see this is implemented differently on each platform. Most examples i get are examples where one is binding the Control in Android Project. WhatUp if my Data binding is done in Xamarin Form (Standard Class) . 1) Can i kindly have the example link or code that refresh any control from a Service that runs in Intervals 2) Update the control that is hosting in a PLC or Standard Class Thanks
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com
-
Good Day All i have a ListView that is defined in a Xamarin Form. i want this ListView to be updated with the Data from the DB every 5 seconds. In a Non Mobile environment , we have a Windows Service , which is a long running Service. but now i search i came across a Service. but now i see this is implemented differently on each platform. Most examples i get are examples where one is binding the Control in Android Project. WhatUp if my Data binding is done in Xamarin Form (Standard Class) . 1) Can i kindly have the example link or code that refresh any control from a Service that runs in Intervals 2) Update the control that is hosting in a PLC or Standard Class Thanks
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com
Service
itself is a concept that is tied to Android platform, you will not find the same concept (check howService
s run, and on which thread), and every platform (iOS, Windows) has its own implementation and best practices for a Service, that is why Xamarin.Forms itself does not have any such library or object. You can however always create your own service that utilize thread pool threads, and runs a job at an interval. Now what you want is a service that services for data, and displays it in theListView
. This has 2 parts, one is the background service that retrieves the data from Windows Service (might it be an API or something that you have!) and the other part is that feeds the data to the UI. This can be solved, if you write a service component, that reads the data inside thePage
. This way yourPage
will have the data that needs to be shown. Now, the last phase of displaying the data can be done usingObservableCollection
, this will automatically map the elements to your ListView. See this for an example of how this can be done, [ListView Data Sources - Xamarin | Microsoft Docs](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/data-and-databinding) So, to wrap, you need to create a (most likely DI based) Service, that will create either a platform dependant or Xamarin.Forms dependant service, and that service should return the data to your Page (an asynchronous API will help even better, enabling your page to refresh only when the data is available without the need of setting a timer and checking for updates), and then lastly bind the data to the page. [How to add background service in Xamarin forms — Xamarin Community Forums](https://forums.xamarin.com/discussion/120332/how-to-add-background-service-in-xamarin-forms)The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
-
Service
itself is a concept that is tied to Android platform, you will not find the same concept (check howService
s run, and on which thread), and every platform (iOS, Windows) has its own implementation and best practices for a Service, that is why Xamarin.Forms itself does not have any such library or object. You can however always create your own service that utilize thread pool threads, and runs a job at an interval. Now what you want is a service that services for data, and displays it in theListView
. This has 2 parts, one is the background service that retrieves the data from Windows Service (might it be an API or something that you have!) and the other part is that feeds the data to the UI. This can be solved, if you write a service component, that reads the data inside thePage
. This way yourPage
will have the data that needs to be shown. Now, the last phase of displaying the data can be done usingObservableCollection
, this will automatically map the elements to your ListView. See this for an example of how this can be done, [ListView Data Sources - Xamarin | Microsoft Docs](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/data-and-databinding) So, to wrap, you need to create a (most likely DI based) Service, that will create either a platform dependant or Xamarin.Forms dependant service, and that service should return the data to your Page (an asynchronous API will help even better, enabling your page to refresh only when the data is available without the need of setting a timer and checking for updates), and then lastly bind the data to the page. [How to add background service in Xamarin forms — Xamarin Community Forums](https://forums.xamarin.com/discussion/120332/how-to-add-background-service-in-xamarin-forms)The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
Thanks for your valuable advice. I used SignalR and it worked for me.