c# - reading a file into stream in windows store App without using async/await -


i want read file assets stream, use following:

public async void loadwidthofunicodesdata() {      string datafile = @"assets\qurandata\data_font1.xml";     storagefolder installationfolder = windows.applicationmodel.package.current.installedlocation;     storagefile file = await installationfolder.getfileasync(datafile);     stream readstream = await file.openstreamforreadasync();                 datacontractserializer ser = new datacontractserializer(typeof(list<unicodewidth>));     widthofunicodes = (list<unicodewidth>)ser.readobject(readstream);     (int = 0; < widthofunicodes.count; i++)     {         widthofunicodesdict.add(widthofunicodes[i].unicode, widthofunicodes[i].width);     } } 

the problem that, part in viewmodel, , it's non-blocking operation, when vm initializes view datacontext, constructor it's supposed fill view exception @ using widthofunicodesdict because it's not yet filled data.

what want do, either make reading stream synchronous method (without using async/await) far don't know how on windows store. or somehow make vm constructor waits till operation finishes , notifies it's done.

you can fetch file without async/await semantics this:

var file = package.current.installedlocation.getfileasync(folder)                .getawaiter()                .getresult(); 

i don't know how stream, can ibuffer or read text, using fileio:

string content = fileio.readtextasync(file).getawaiter().getresult(); ilist lines = fileio.readlinesasync(file).getawaiter().getresult(); ibuffer buffer = fileio.readbufferasync(file).getawaiter().getresult(); 

i've done before , doesn't cause deadlocks.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -