Snoop.SnoopUI.CheckForOtherDispatchers C# (CSharp) Method

CheckForOtherDispatchers() private static method

private static CheckForOtherDispatchers ( Dispatcher mainDispatcher ) : void
mainDispatcher System.Windows.Threading.Dispatcher
return void
        private static void CheckForOtherDispatchers(Dispatcher mainDispatcher)
        {
            // check and see if any of the root visuals have a different mainDispatcher
            // if so, ask the user if they wish to enter multiple mainDispatcher mode.
            // if they do, launch a snoop ui for every additional mainDispatcher.
            // see http://snoopwpf.codeplex.com/workitem/6334 for more info.

            List<Visual> rootVisuals = new List<Visual>();
            List<Dispatcher> dispatchers = new List<Dispatcher>();
            dispatchers.Add(mainDispatcher);
            foreach (PresentationSource presentationSource in PresentationSource.CurrentSources)
            {
                Visual presentationSourceRootVisual = presentationSource.RootVisual;

                if (!(presentationSourceRootVisual is Window))
                    continue;

                Dispatcher presentationSourceRootVisualDispatcher = presentationSourceRootVisual.Dispatcher;

                if (dispatchers.IndexOf(presentationSourceRootVisualDispatcher) == -1)
                {
                    rootVisuals.Add(presentationSourceRootVisual);
                    dispatchers.Add(presentationSourceRootVisualDispatcher);
                }
            }

            if (rootVisuals.Count > 0)
            {
                var result =
                    MessageBox.Show
                    (
                        "Snoop has noticed windows running in multiple dispatchers!\n\n" +
                        "Would you like to enter multiple dispatcher mode, and have a separate Snoop window for each dispatcher?\n\n" +
                        "Without having a separate Snoop window for each dispatcher, you will not be able to Snoop the windows in the dispatcher threads outside of the main dispatcher. " +
                        "Also, note, that if you bring up additional windows in additional dispatchers (after Snooping), you will need to Snoop again in order to launch Snoop windows for those additional dispatchers.",
                        "Enter Multiple Dispatcher Mode",
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Question
                    );

                if (result == MessageBoxResult.Yes)
                {
                    SnoopModes.MultipleDispatcherMode = true;
                    Thread thread = new Thread(new ParameterizedThreadStart(DispatchOut));
                    thread.Start(rootVisuals);
                }
            }
        }