Handle Disconnection

Hello,

I have an application with authentication. After authentication i'm using requests to sever with the authenticated cookie.
when a request returns as "disconnected" (Unauthenticated) i want to move the user to the login page.
My code is written like this:

    var getDataTask= GetDataRequest();
    await getDataTask;
var dataRequestResult = getDataTask.Result;
// code after get data

public async Task<object> GetDataRequest()
{
  object datafromserver;
  // get data from server
  if (datafromserver.IsDisconnected)
  {
    App.Current.MainPage = new LoginPage();
    // Cancel <- how to cancel?
  }
  else
  {
    return datafromserver;
  }
}

In the GetDataRequest I cant move the user to the LoginPage. the problem is that this code still waits for "getDataTask".
is there a way to "cancel" the code after GetDataRequest if the request returned as disconnected?
cancel the task and the code afterwards? (I mean without checking if the task is canceled and without try and catch)

Sign In or Register to comment.