Sunday, September 22, 2013

C#: Perform the action on the thread the Control was created.


        /// <summary>
        /// Perform the action on the thread the <see cref="Control"/> was created.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="action"></param>
        public static void InvokeIfRequired( this Control control, Action action ) {
            if ( control.InvokeRequired ) {
                control.BeginInvoke( action );
            }
            else {
                action();
            }
        }

No comments: