Esempio n. 1
0
        /// <summary>
        /// Invokes a method after the provided time span
        /// </summary>
        /// <returns>
        /// A timer object
        /// </returns>
        /// <param name='action'>
        /// The action to execute.
        /// </param>
        /// <remarks>
        /// This method schedules the execution of the provided function. The function
        /// must return 'true' if it has to be executed again after the time span, or 'false'
        /// if the timer can be discarded.
        /// The execution of the funciton can be canceled by disposing the returned object.
        /// </remarks>
        public static IDisposable TimeoutInvoke(TimeSpan timeSpan, Func <bool> action)
        {
            Timer t = new Timer();

            t.Id = engine.TimeoutInvoke(action, timeSpan);
            return(t);
        }
Esempio n. 2
0
        /// <summary>
        /// Invokes an action in the GUI thread after the provided time span
        /// </summary>
        /// <returns>
        /// A timer object
        /// </returns>
        /// <param name='action'>
        /// The action to execute.
        /// </param>
        /// <remarks>
        /// This method schedules the execution of the provided function. The function
        /// must return 'true' if it has to be executed again after the time span, or 'false'
        /// if the timer can be discarded.
        /// The execution of the funciton can be canceled by disposing the returned object.
        /// </remarks>
        public static IDisposable TimeoutInvoke(TimeSpan timeSpan, Func <bool> action)
        {
            Timer t = new Timer();

            t.Id = engine.TimeoutInvoke(delegate {
                bool res = false;
                try {
                    Toolkit.EnterUserCode();
                    res = action();
                    Toolkit.ExitUserCode(null);
                } catch (Exception ex) {
                    Toolkit.ExitUserCode(ex);
                }
                return(res);
            }, timeSpan);
            return(t);
        }