using System;
using System.Windows.Forms;

namespace IOB_WIN_FORM
{
    /// <summary>
    /// Helper gestione UIThread e deleghe
    /// https://www.codeproject.com/Articles/37642/Avoiding-InvokeRequired
    /// </summary>
    internal static class ControlExtensions
    {
        #region Public Methods

        public static void UIThread(this Control control, Action code)
        {
            if (control.InvokeRequired)
            {
                control.BeginInvoke(code);
                return;
            }
            code.Invoke();
        }

        public static void UIThreadInvoke(this Control control, Action code)
        {
            if (control.InvokeRequired)
            {
                control.Invoke(code);
                return;
            }
            code.Invoke();
        }

        #endregion Public Methods
    }
}