Protected void Page_Load(object sender, EventArgs e)
{
XDocument response = ThirdPartyAPI.HttpRequest(someParams);
if(response != null)
{
var node = response.Root.Elements("documents").Elements("document");
string url = node.ElementAt(0).Element("url").Value;
UploadFileToXYZSiteWithHttpRequest(token, parentID,url);
}
}
My scenario as following:
My problem here is that the response variable is
null when my project is running.
But when I am debugging and put a breakpoint before the response variable and wait for some few seconds, lets say 3 seconds, I get the response I am expecting.
It seems that I have to wait for some seconds before executing HttpRequest() function in order have a response.
I tried putting the Thread.Sleep(3000) method before the mentioned code line but now my second function (
UploadFileToXYZSiteWithHttpRequest) its not doing its work.
Should I wait for something to finish (I don't know what, may be the page load, a thread that its in the background) for then to execute the ThirdPartyAPI.HttpRequest method?
should I use Threads or Task<tresult> class or anything else? if so, how to achieve this?
Please help me to clarify my way to solve this.
thanks.