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

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -