QueueUserWorkItem messes up UI

LexxpsLexxps Member
edited August 2019 in Xamarin.Forms

Hey guys,
I have been working on a project for some time now and yesterday i discovered a bug about the ThreadPool.QueueUserWork-Function.
After queuing a function in the ThreadPool I tried going one page back in my app and the ToolBarItems disappeared. Then I tried to open an other Page and it just shows a blank page with ToolBar.
Here is like I have done this

private void Button_Click(object sender, EventArgs e){
    ThreadPool.QueueUserWorkItem(o => my_function());

private async Task my_function(){
    //Do some stuff (In my case sending to WebService what will ofcourse need some time)

After the Button_clicked was triggered and i go back to mainPage the ToolBarItems are missing and other pages show blank with toolbar as already mentioned.

I already tried around by making my_function synchronous instead of asynchronous but not working...
Since this Operation in my_function can take upto 10 seconds or even more I really can't block the UI (this would be terrible for UX)

The only things that fixes this is rotating the screen or going to app recents and back to the app itself btw... After doing this everything gets normal again

I have never had this before and compared with older version of the App because I thought i messed up somewhere but it was always like this and working before somehow.

Would be really great if u guys can help me and know any solution bc as I said, I can't block UI...


If this could be any help, I guess it's due to the App/Xamarin thinking while switching back I am still in ThreadPool and so it cant handle UI
Looks like it just isn't redrawing the UI and mixing it up with other pages...
After this nothing will work right until u leave and resume the app

Sign In or Register to comment.