Issue
Why is the UI blocked when I load data from the server using an async
request as follows:
public ObservableCollection<VideoFile> VideoFiles { get; private set; } = new ObservableCollection<VideoFile>();
private void LoadVideoFiles(string categoryId = "*", int page = 1)
{
_videoFiles = NotifyTask.Create(_videoManager.GetVideoFilesAsync(_videoFileSearchParam));
_videoFiles.PropertyChanged -= VideoFilesPropertyChanged;
_videoFiles.PropertyChanged += VideoFilesPropertyChanged;
}
private void VideoFilesPropertyChanged(object sender, PropertyChangedEventArgs propertyName)
{
foreach (var videoFile in ((NotifyTask<List<VideoFile>>)sender).Result)
{
VideoFiles.Add(videoFile);
}
}
Solution
UI is being blocked because calls you are making are synchronous, thus app will wait with the whole thread until this call ends.
If you want to make UI responsive in the meantime you should make method asynchronous using async
keyword.
This way it will let method run, while all other UI elements will stay responsive. You can read more here
Answered By - Adam Kaczmarski
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.