Catel.Windows.Threading.DispatcherHelper.GetCurrentDispatcher C# (CSharp) Method

GetCurrentDispatcher() private static method

Gets the current dispatcher.
private static GetCurrentDispatcher ( ) : global::Windows.UI.Core.CoreDispatcher
return global::Windows.UI.Core.CoreDispatcher
        private static Dispatcher GetCurrentDispatcher()
        {
#if NET
            var currentApplication = System.Windows.Application.Current;
            if (currentApplication != null)
            {
                return currentApplication.Dispatcher;
            }
            
            return Dispatcher.CurrentDispatcher;
#elif NETFX_CORE
            var firstView = global::Windows.ApplicationModel.Core.CoreApplication.Views.FirstOrDefault();
            if (firstView != null)
            {
                return firstView.Dispatcher;
            }

            var window = Window.Current;
            if (window != null)
            {
                return window.Dispatcher;
            }

            return null;
#else
            try
            {
                if ((Application.Current != null) && (Application.Current.RootVisual != null))
                {
                    return Application.Current.RootVisual.Dispatcher;
                }
            }
            catch (Exception)
            {
                // Possible when running unit tests, swallow
            }

            try
            {
                if (Deployment.Current != null)
                {
                    return Deployment.Current.Dispatcher;
                }
            }
            catch (Exception)
            {
                // Possible when running unit tests, swallow
            }

            return null;
#endif
        }
    }