Hi,
I have created app in Xamarin.Forms. On one page we are showing images in ListView by weburl. We are checking whether file is exists or not on web by using below code.
This function is executing synchronously but we need not wait upto the execution of this code we want to it run asynchronously.
Is there anyone know how to convert below code that can run this function asynchronously?
Thanks in advance.
public bool IsFileExist(string filePath)
{
bool isExist = false;
try
{
if (!string.IsNullOrEmpty(filePath))
{
//Creating the HttpWebRequest
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(filePath);
//Setting the Request method HEAD, you can also use GET too.
request.Method = "HEAD";
//Getting the Web Response.
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (response != null)
{
if (response.StatusCode == HttpStatusCode.OK) //Returns TURE if the Status code == 200
isExist = true;
}
}
}
}
catch
{
}
return isExist;
}