❔ Load async data and display it (WindowsAppSDK / WinUI3)
I am currently developing my first windows app with C#, Windows App SDK and WinUI3. I want to do something very basic. Load a list of items and display it in the UI. My problem is, that the method to load the data has to be executed asynchronously because it would block the UI thread. I didn't find any working information about how to do that. Like, it should be a simple solution right? Can anyone help me with that?
4 Replies
Just like that
Doesn't work. The UI is not responding for a moment...
Here is my code
And another thing...
My app is crashing if I try to use this in xaml
I don't know too much about WinUI3, but you can use the
Page.Loaded
-Event to at least have an async method, that allows you to call await LoadDevices()
Btw LoadDevices
should return a Task
So that could look like
you just need to subscribe to that event somewhere
The way you were calling LoadDevices
wont work because it'll start executing the method and then, the program will forget about it. It wont wait for any results or changes this method might make because you are not awaiting it.
Trying to put await
before the call in the constructor will also not work because constructors cannot be async.Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.