private async Task StartLogin()
        {
            EnableProgressRingAndHideButtons();
            string email    = Email_box.Text;
            string password = Password_box.Password;

            if (email == "" || password == "")
            {
                await ShowLoginErrorDialog("Please type login and password");

                DisableProgressRingAndShowButtons();
                return;
            }
            string selectedVersion = "MSNP15";

            if (localSettings.Values["MsnpVersion"] != null)
            {
                selectedVersion = localSettings.Values["MsnpVersion"].ToString();
            }
            bool usingLocalhost = false;

            if (localSettings.Values["UsingLocalhost"] != null)
            {
                usingLocalhost = (bool)localSettings.Values["UsingLocalhost"];
            }
            string initialStatus = PresenceStatuses.Available;

            switch (InitialStatusBox.SelectedItem.ToString())
            {
            case "Available":
                initialStatus = PresenceStatuses.Available;
                break;

            case "Busy":
                initialStatus = PresenceStatuses.Busy;
                break;

            case "Away":
                initialStatus = PresenceStatuses.Away;
                break;

            case "Invisible":
                initialStatus = PresenceStatuses.Hidden;
                break;
            }
            notificationServerConnection = new NotificationServerConnection(email, password, usingLocalhost, selectedVersion, initialStatus);
            if (localSettings.Values["KeepHistory"] != null)
            {
                notificationServerConnection.KeepMessagingHistoryInSwitchboard = (bool)localSettings.Values["KeepHistory"];
            }
            try
            {
                await notificationServerConnection.LoginToMessengerAsync();
            }
            catch (AggregateException ae)
            {
                for (int i = 0; i < ae.InnerExceptions.Count; i++)
                {
                    await ShowLoginErrorDialog(ae.InnerExceptions[i].Message);
                }
                DisableProgressRingAndShowButtons();
                return;
            }
            catch (NullReferenceException)
            {
                await ShowLoginErrorDialog("Incorrect email or password");

                DisableProgressRingAndShowButtons();
                return;
            }
            catch (SocketException se)
            {
                await ShowLoginErrorDialog("Server connection error, " + se.Message);

                DisableProgressRingAndShowButtons();
                return;
            }
            catch (Exception e)
            {
                await ShowLoginErrorDialog(e.Message);

                DisableProgressRingAndShowButtons();
                return;
            }
            App app = Application.Current as App;

            app.NotificationServerConnection = notificationServerConnection;
            this.Frame.Navigate(typeof(ContactList), notificationServerConnection);
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     notificationServerConnection = null;
     DisableProgressRingAndShowButtons();
     base.OnNavigatedTo(e);
 }