- Home /
In c#, how to yield until a download is complete?
Ok, I'm trying retreive data from a php file that access a database. That works fine. At the moment I'm using a javascript file to access the php file, which also works fine.
But I want to use a c# version as I've got custom c# classes that will mold the data.
The one thing I've not been able to convert to c# is the yield part below:
// Post the URL to the site and create a download object to get the result. hs_get = WWW(check_url);
yield hs_get; // Wait until the download is done
I understand that i need to use coroutines. However all the examples use a prespecified time. Where as the javascript above doesn't use any as it waits until the transfer/download is complete. what would be an equilvalent in c#?
Answer by Peter G · Jan 15, 2011 at 12:19 AM
Use yield return WWW
to wait for completion
void Download () { StartCoroutine(FinishDownload(url)); //In C#, you have to explicitly start a corotine. }
IEnumerator FinishDownload (string url) { WWW hs_get = new WWW(url);
yield return hs_get;
//Work with the retrieved info.
}
Your answer
Follow this Question
Related Questions
downloading data via coroutine in Update() 0 Answers
Why does nothing happen after yield return www 0 Answers
Wait for file download 1 Answer
WWW/ yield calls throwing errors on iPad 1 Answer
How can I use yield in C# 3 Answers