DispatcherService extensions

Topics: Feature requests
Sep 8, 2012 at 4:07 PM
Edited Sep 8, 2012 at 4:08 PM

Hi Geert,

i've seen that you changed the DispatcherService (BeginInvoke).
Would it be possible to introduce some more functions to the IDispatcherService
to allow finer control (to increase speed performance and so on....)?

Here is one example to demonstrate what i mean:

       public void BeginInvokeIfRequired(Action action)
        {
            Argument.IsNotNull("action", action);

            var dispatcher = CurrentDispatcher;
            if ((dispatcher != null) && !dispatcher.CheckAccess())    //<------------
            {
#if NETFX_CORE
                dispatcher.BeginInvoke(action);
#else
                dispatcher.BeginInvoke(action, null);
#endif
            }
            else
            {
                action.Invoke();
            }
        }

        public void BeginInvoke(Action action)
        {
            Argument.IsNotNull("action", action);

            var dispatcher = CurrentDispatcher;
            if (dispatcher != null)
            {
#if NETFX_CORE
                dispatcher.BeginInvoke(action);
#else
                dispatcher.BeginInvoke(action, null);
#endif
            }
            else
            {
                action.Invoke();
            }
        }

Many Thanks!

Coordinator
Sep 8, 2012 at 9:47 PM

We will consider it for 3.4

Sep 10, 2012 at 10:26 AM

Thanks for taking it into account...

Coordinator
Sep 23, 2012 at 2:01 PM

Internally, we created this method:

        private void BeginInvoke(Action action, bool onlyBeginInvokeWhenNoAccess)
        {
            Argument.IsNotNull("action", action);

            bool actionInvoked = false;

            var dispatcher = CurrentDispatcher;
            if (dispatcher != null)
            {
                if (!onlyBeginInvokeWhenNoAccess || !dispatcher.CheckAccess())
                {
#if NETFX_CORE
                    dispatcher.BeginInvoke(action);
#else
                    dispatcher.BeginInvoke(action, null);
#endif

                    actionInvoked = true;
                }
            }

            if (!actionInvoked)
            {
                action.Invoke();
            }
        }

This way, we can easily create overloads.

Coordinator
Sep 23, 2012 at 2:05 PM

Feature implemented and committed. Please let me know if this is what you meant.

Sep 28, 2012 at 10:09 PM

Sorry for being late with my reply. It works perfectly. Many thanks for this quick update!