I have many apis calls in a single page. The approach i am currently using is start a await Task.Run(() thread, do fetch operation, start Main Thread and do UI operations. The app works smooth but after few navigation, it stops responding. With some research it found thus can be due to main thread. Is this the correct way implementation, that i am using?
await Task.Run(() => { fetchdata(); fetchData2(); fetchData3(); MainThread.BeginInvokeOnMainThread(() => { //UI changes }: });
@exendahal said:
I am getting warning from main thread.
What is the warning?
@exendahal said:
I have many apis calls in a single page. The approach i am currently using is start a await Task.Run(() thread, do fetch operation, start Main Thread and do UI operations. The app works smooth but after few navigation, it stops responding. With some research it found thus can be due to main thread. Is this the correct way implementation, that i am using?await Task.Run(() => { fetchdata(); fetchData2(); fetchData3(); MainThread.BeginInvokeOnMainThread(() => { //UI changes }:
What is MainThread? Why not simply use Device.BeginInvokeOnMainThread
?
Post the content of fetchdata(), fetchData2() and fetchData3()
Post an example of a "UI change"
Do you start a new Task each time you navigate? Do you ever stop the Tasks, or do you end up with multiple Tasks doing the same thing?
This issue was resolved using http client instead of web request. Thanks to JohnHardnan.
Answers
What exactly do you mean by "UI changes"? Are you using bindings to display your data?
What is the warning?
What is MainThread? Why not simply use
Device.BeginInvokeOnMainThread
?Post the content of fetchdata(), fetchData2() and fetchData3()
Post an example of a "UI change"
Do you start a new Task each time you navigate? Do you ever stop the Tasks, or do you end up with multiple Tasks doing the same thing?
Here is code behind the homepage.
I see similar issues like below.
https://github.com/mono/SkiaSharp/issues/998
This issue was resolved using http client instead of web request. Thanks to JohnHardnan.