Example #1
0
        /// <summary>
        /// Filtered invokes make sure only one instance of the given method call is in action at the given moment.
        /// This is usefull for calls that are made very many times, but we wish to allow the control to only
        /// process as much as it can in real time (not delaying any calls for later).
        /// Filtering is done on a method AND instance basis, so if you have 2 instances of same class alive,
        /// they will not interupt each others calls and each of them will receive what is due.
        /// </summary>
        /// <param name="minimumInterInvocationInterval">The interval between two consecutive invokes of the method; pass null for default; TimeSpan.Zero for immediate (based on a 100ms timer, so delay up to 100ms).</param>
        /// <returns>Result shows if the given invoke was placed, or if there is another one pending executing and this one was dropped.</returns>
        public static bool BeginFilteredManagedInvoke(Control control, TimeSpan minimumInterInvocationInterval, Delegate d, params object[] args)
        {
            MethodInvocationInformation information = null;

            // Obtain the corresponding invocation information item.
            lock (_filteredInvokes)
            {
                if (_filteredInvokes.ContainsKey(control) == false)
                {
                    _filteredInvokes.Add(control, new Dictionary <MethodInfo, MethodInvocationInformation>());
                }

                Dictionary <MethodInfo, MethodInvocationInformation> dictionary = _filteredInvokes[control];

                if (dictionary.ContainsKey(d.Method) == false)
                {
                    information = new MethodInvocationInformation(control, d);
                    dictionary.Add(d.Method, information);
                }
                else
                {
                    information = dictionary[d.Method];
                }
            }

            return(information.Invoke(minimumInterInvocationInterval, args));
        }
        /// <summary>
        /// Filtered invokes make sure only one instance of the given method call is in action at the given moment.
        /// This is usefull for calls that are made very many times, but we wish to allow the control to only
        /// process as much as it can in real time (not delaying any calls for later).
        /// Filtering is done on a method AND instance basis, so if you have 2 instances of same class alive,
        /// they will not interupt each others calls and each of them will receive what is due.
        /// </summary>
        /// <param name="minimumInterInvocationInterval">The interval between two consecutive invokes of the method; pass null for default; TimeSpan.Zero for immediate (based on a 100ms timer, so delay up to 100ms).</param>
        /// <returns>Result shows if the given invoke was placed, or if there is another one pending executing and this one was dropped.</returns>
        public static bool BeginFilteredManagedInvoke(Control control, TimeSpan minimumInterInvocationInterval, Delegate d, params object[] args)
        {
            MethodInvocationInformation information = null;

            // Obtain the corresponding invocation information item.
            lock (_filteredInvokes)
            {
                if (_filteredInvokes.ContainsKey(control) == false)
                {
                    _filteredInvokes.Add(control, new Dictionary<MethodInfo, MethodInvocationInformation>());
                }

                Dictionary<MethodInfo, MethodInvocationInformation> dictionary = _filteredInvokes[control];

                if (dictionary.ContainsKey(d.Method) == false)
                {
                    information = new MethodInvocationInformation(control, d);
                    dictionary.Add(d.Method, information);
                }
                else
                {
                    information = dictionary[d.Method];
                }
            }

            return information.Invoke(minimumInterInvocationInterval, args);
        }