private Thread StartUIThread()
        {
            // Start a new UI thread to run the browser dialog on so that we can block this one and present
            // a synchronous interface to callers.
            Thread uiSubThread = new Thread(
                () =>
            {
                try
                {
                    this.formsSyncContext = new WindowsFormsSynchronizationContext();

                    this.dialog = new SilentWindowsFormsAuthenticationDialog(this.OwnerWindow)
                    {
                        NavigationWaitMiliSecs = NavigationWaitMiliSecs
                    };

                    Uri promptNeverRequestUri = AmendRequestUriWithPromptNever(this.RequestUri);
                    this.dialog.Done         += this.UIDoneHandler;

                    this.threadInitializedEvent.Set();

                    this.dialog.AuthenticateAAD(promptNeverRequestUri, this.CallbackUri);

                    // Start and turn control over to the message loop.
                    Application.Run();

                    this.result = this.dialog.Result;
                }
                catch (Exception e)
                {
                    // Catch all exceptions to transfer them to the original calling thread.
                    this.uiException = e;
                }
            });

            uiSubThread.SetApartmentState(ApartmentState.STA);
            uiSubThread.IsBackground = true;
            uiSubThread.Start();

            return(uiSubThread);
        }
Пример #2
0
        private Thread StartUIThread()
        {
            // Start a new UI thread to run the browser dialog on so that we can block this one and present
            // a synchronous interface to callers.
            Thread uiSubThread = new Thread(
                () =>
                {
                    try
                    {
                        this.formsSyncContext = new WindowsFormsSynchronizationContext();

                        this.dialog = new SilentWindowsFormsAuthenticationDialog(this.OwnerWindow)
                        {
                            NavigationWaitMiliSecs = NavigationWaitMiliSecs
                        };

                        this.dialog.Done += this.UIDoneHandler;

                        this.threadInitializedEvent.Set();

                        this.dialog.AuthenticateAAD(this.RequestUri, this.CallbackUri);

                        // Start and turn control over to the message loop.
                        Application.Run();

                        this.result = this.dialog.Result;
                    }
                    catch (Exception e)
                    {
                        // Catch all exceptions to transfer them to the original calling thread.
                        this.uiException = e;
                    }
                });

            uiSubThread.SetApartmentState(ApartmentState.STA);
            uiSubThread.IsBackground = true;
            uiSubThread.Start();

            return uiSubThread;
        }