Note that there are some explanatory texts on larger screens.

plurals
  1. POStuck at async method
    primarykey
    data
    text
    <p>There maybe some obvious mistake but I'm doing something not experienced with. I'm trying to get a string from internet but its not working. In WinRT, we have to use HttpClient in async method, which I did as follows:-</p> <pre><code> private async void update() { try { rawdata = await client.GetStringAsync(url); } catch { rawdata = "Updation failed. Error code:vish42042"; } } </code></pre> <p>Now, here is how the code is called:-</p> <pre><code> string temp = @url; update(); WAIT: if (rawdata == null) { goto WAIT; } </code></pre> <p>rawdata is a global varible, I did this checking on goto WAIT: to see where exactly was code failing, and its failing here. I'm expecting the if loop to break when rawdata is updated from the internet, but it never happens. Am I doing it the wrong way?(OBVIOUSLY I'm not doing it in the best way I know, but is it wrong too?). Where is the problem?</p> <p>Update: Actually the problem is not HOW TO MAKE THIS FUNCTION WORK, it is working with a modification or two. The real problem is how do I make sure that rawdata is updated once update() function is called, because the code thereafter is expecting it not to be null but updated.</p> <p>After some very good explanations and answers, I think then this is the point where problem can be solved:-</p> <pre><code> string xmlstring = xmlupobj.getUpdatedData(); // Above is the ultimate point of return of data. //Next code line is this, which throws a null exception XDocument xmldoc = XDocument.Parse(xmlstring); </code></pre> <p>So I think after making getUpdatedData() async, returning Task, if we can convert Task to proper string in case it has been downloaded, and null if it has not been downloaded, then we can check using some bad lines of code as:-</p> <pre><code> string xmlstring = xmlupobj.getUpdatedData(); WAIT: if (xmlstring == null) { goto WAIT; } xmldoc = XDocument.Parse(xmlstring); </code></pre> <p>So if it is right, the only question remains is how to set xmlstring?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload