Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

MultiRequest in xamarin PCL

xamarin7897xamarin7897 USMember ✭✭
edited July 2017 in Xamarin.Forms

HI,
I have firing two async Httpwebrequest. One has a timeout of 1 minute, so i wait for the response until one minute[I do need this response, to update UI]. In the mean time, If i fire another async httpwebrequest, its response isnt returned until my first request's response is received. Is there a way to handle this.

Is it possible to set the priority on the httpwebrequest Or any other best way to handle it...
`` the method to get the rsponse
public static Task GetResponseAsync(HttpWebRequest request)
{
var taskComplete = new TaskCompletionSource();
try
{
request.BeginGetResponse(asyncResponse =>
{
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.EndGetResponse(asyncResponse);
if (response != null)
{
if (response.StatusCode == System.Net.HttpStatusCode.OK)
taskComplete.SetResult(response);
}
}
catch (WebException exc)
{
exc.GetBaseException();
taskComplete.SetResult(null);
request.Abort();
return;
}
}, request);

        }
        catch (Exception ex)
        {
            //Console.WriteLine(ex.InnerException);
            taskComplete.SetResult(null); request.Abort();
        }
        return taskComplete.Task;
    }

Answers

  • xamarin7897xamarin7897 USMember ✭✭
    edited July 2017

    # the method to get the rsponse``
    public static Task GetResponseAsync(HttpWebRequest request)
    {
    var taskComplete = new TaskCompletionSource();
    try
    {
    request.BeginGetResponse(asyncResponse =>
    {
    HttpWebResponse response = null;
    try
    {
    response = (HttpWebResponse)request.EndGetResponse(asyncResponse);
    if (response != null)
    {
    if (response.StatusCode == System.Net.HttpStatusCode.OK)
    taskComplete.SetResult(response);
    }
    }
    catch (WebException exc)
    {
    exc.GetBaseException();
    taskComplete.SetResult(null);
    request.Abort();
    return;
    }
    }, request);
    }
    catch (Exception ex)
    {
    //Console.WriteLine(ex.InnerException);
    taskComplete.SetResult(null); request.Abort();
    }
    return taskComplete.Task;

Sign In or Register to comment.