wpf - Reading file async still blocks the UI -
i have simple treeview, when click on treeview item load text file
here code:
private async void notestreeview_onselecteditemchanged(object sender, routedpropertychangedeventargs<object> e) { var clickedmodel = e.newvalue treefileitem; if (clickedmodel != null && file.exists(clickedmodel.filepath)) { _viewmodel.noteloadinginprogress = true; using (var reader = file.opentext(clickedmodel.filepath)) { var filecontent = await reader.readtoendasync(); _viewmodel.activenote = filecontent; } _viewmodel.noteloadinginprogress = false; } } this works, when click on treeview item ui frozen, until file read complete. why such behavior? have other async methods in code , don't block ui.
edit: seems issue not in reading file, in setting large amount of text textbox.text properti via databinding, though setting directly take lot of time , make ui freeze
the ui frozen, until file read complete
streams opened file.opentext never asynchronous. describe on blog, must open file using method isasync parameter (set true) or fileoptions parameter (including fileoptions.asynchronous value).
it seems issue not in reading file, in setting large amount of text textbox.text properti via databinding
yes, ui elements not intended used huge amounts of data. need use virtualization if have large amounts of data display.
Comments
Post a Comment