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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -