i seeing odd behavior async methods. discovered unzipping entire zip archive not performant on windows devices. so i've resorted extracting single file need, using while wait rest of archive extract. however, code extract single file , code extract entire archive being called same method. method async , called on ui thread code in app.xaml.cs. when call method, using await keyword wait complete there 1 file in zip archive need loading of app.
app.xaml looks this:
sharedcontext.changeuniverse("1234");
sharedcontext looks this:
public static void changeuniverse(string universe) { await downloadarchive(universe); } public async task downloadarchive(string universe) { ziparchive archive = magic; // somehow var somelocalfilepath = magic; // exact location need extract data.json var somelocalpath = magic; // exact location need extract zip archive.getentry("data.json").extracttofile(somelocalfilepath); // notice not await extractfullarchive(archive, somelocalpath); } public async task extractfullarchive(ziparchive archive, string path) { archive.extracttodirectory(path, true); // extracting using override nice extension method found on so.com }
the problem downloadarchive doesn't return until extractfullarchive completes , extractfullarchive taking long time. need extractfullarchive execute asynchronously while downloadarchive completes. don't care when finishes.
dont return task if don't want wait instead return void this
public async void extractfullarchive(ziparchive archive, string path) { archive.extracttodirectory(path, true); // extracting using override nice extension method found on so.com }
Comments
Post a Comment