private async void SignIn()

in TrayListener/MainWindow.xaml.cs [331:375]


        private async void SignIn(object sender = null, RoutedEventArgs args = null)
        {
            if (IsAuthenticated())
            {
                SignOut();
            }

            // Get an access token to call the To Do list service.
            AuthenticationResult result = null;
            try
            {
                result = await authContext.AcquireTokenAsync(graphResourceId, aadClientId, redirectUri, new PlatformParameters(PromptBehavior.Always));
                UpdateSignInUIState(result.UserInfo);
                try
                {
                    InitializeSignalR();
                }
                catch (Exception ex)
                {
                    // Note: 500 error often indicates authentication issues (was redirected to a 401 response or MS authentication page, which cannot be parsed)
                    string message = "Could not initialize SignalR listener, please restart the application and try again.If the issue persists, contact your system administrator.";
                    message += "\nException: " + ex.Message;
                    if (ex.InnerException != null) message += "\nInner Exception : " + ex.InnerException.Message;
                    MessageBox.Show(message);
                }
            }
            catch (AdalException ex)
            {
                if (ex.ErrorCode == "authentication_canceled")
                {
                    // The user canceled sign in
                    UpdateSignInUIState();
                }
                else
                {
                    string message = "An unexpected error occured.";
                    message += "\n Exception: " + ex.Message;
                    if (ex.InnerException != null) message += "\nInner Exception : " + ex.InnerException.Message;
                    MessageBox.Show(message);
                }

                return;
            }

        }