c# - How can I return a string from an async operation? -
i'm using pclstorage , need way read file. i'm going use json serialization, need read saved content file:
public async string readfromfile(string filename) { ifolder rootfolder = filesystem.current.localstorage; ifolder folder = await rootfolder.createfolderasync("mysubfolder", creationcollisionoption.openifexists); ifile file = await folder.getfileasync(filename); string content = await file.readalltextasync(); return content; }
but cant return string, has void, task or task.
is there easy way can return string method? maybe invoking method?
you need return task<string>
, this:
public async task<string> readfromfile(string filename) { ifolder rootfolder = filesystem.current.localstorage; ifolder folder = await rootfolder.createfolderasync("mysubfolder", creationcollisionoption.openifexists); ifile file = await folder.getfileasync(filename); string content = await file.readalltextasync(); return content; }
Comments
Post a Comment