c# - Return from asyncCallBack -


following tutorial http://msdn.microsoft.com/en-us/library/hh221581.aspx created httpwebrequest.

producing code callback function:

    private void readcallback(iasyncresult result)     {          httpwebrequest request = result.asyncstate httpwebrequest;          if (request != null)         {             try             {                 webresponse response = request.endgetresponse(result);                  using (streamreader streamreader1 = new streamreader(response.getresponsestream()))                 {                     string resultstring = streamreader1.readtoend();                 }             }             catch (webexception e)             {                 return;             }         }     } 

now got data in resultstring, can't return normal way because of call being async (as 1 can read here: asynccallback - have static / have return void?).

i can create global variables , safe resultstring global access everywhere, don't think proper way this. msdn writes results console (http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.95).aspx), not thing want to.

is there "best practice" or proceeding results form async calls (for using them in other methods called later on?


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -