0

I have created an authentication library in wp8 which requires me to provide a login screen UI and return the session id and other login details on authentication with server.. I have an API which returns the login data..

Now in the app im going to the login screen using NavigationService.navigate () which automatically instantiates my library class..

My Question is how do I get the reference to object of class that is instantiated by navigate method.. Also it seems that navigate() is asynchronous as it shows my login page and immediately moves to the line after the call.. My requirement is that I have to call the API that returns login data only after authentication has been performed but I have no reference of the instantiated object to call it

Is there any way to make the navigate() wait until the authentication is complete?

user3604958
  • 101
  • 7
  • can't you use Navigate directly after authentication till you can display loading... – vITs May 19 '14 at 09:51
  • To authenticate I need the username and password which is input from the login screen which I go to by calling navigate.. – user3604958 May 19 '14 at 10:15

1 Answers1

0

You are getting username and password from login screen and you are using this data for authentication.then,you can call your API in login screen's "say Login" button and after that you can use event delegate mechanism to receive web service response status, if its correct then you can navigate to next screen,till then you can use ProgressBar.

please check this code to get understanding of await:

    Object response = await Authenticate(UsernameTextBox.Text, PasswdTextBox.Password);

    if (response is success)//typecast your object as per your need to get status of result
    {
      Navigate
    }
    else
    {
     Show error dialog
    }

Also dont forget to modify your button event handler's signature with "async".

vITs
  • 1,651
  • 12
  • 30
  • is there any way I can make the navigate() wait until the SubmitButton_click event on my login screen is completed before it returns? – user3604958 May 19 '14 at 10:44
  • 1
    ok...you can call your Authenticate web service on click with "await" so that it will return responce into some object.it will wait till responce comes.then you can navigate as per required response. – vITs May 19 '14 at 12:00
  • can you give some details on how I can do this? – user3604958 May 20 '14 at 06:21
  • please check i have edited answer with code snippet so that your idea will get cleared.as we used "await" it will wait till we get Authentication response.Hope this Helped you.If yes don't forget to accept this answer. – vITs May 20 '14 at 06:50