Beispiel #1
0
        /// <summary>
        /// Queue a new UI task with given delay interval and optional context.
        /// </summary>
        /// <param name="task">The task to execute</param>
        /// <param name="context">The context to pass to the task when it is being called on the UI thread</param>
        /// <param name="interval">The interval at which to pump the task</param>
        /// <returns>The cancellable result</returns>
        public static ICancellableAsyncResult BeginExecuteTask(TaskForUIThread task, object context, TimeSpan interval)
        {
            if (!initialized)
            {
                throw new InvalidOperationException("UIThreadClassNotInitialized");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            TaskData taskData = new TaskData(task, context, interval);

            if (terminated)
            {
                taskData.Cancel(); // can't run it if UI has terminated.
                return(taskData);
            }

            lock (uiTasks)
            {
                // add the task
                uiTasks.Add(taskData);
                Start();
            }
            return(taskData);
        }
Beispiel #2
0
 private void Execute(TaskData data, ILogDataAccessor <TIndex, TData> accessor)
 {
     try
     {
         TData value;
         if (accessor.TryAccess(data.Index, out value))
         {
             data.Finished(value);
         }
         else
         {
             // If this region of data can no longer be accessed,
             // then we cancel the request.
             data.Cancel();
         }
     }
     catch (Exception e)
     {
         Log.ErrorFormat("Caught unexpected exception");
         data.Failed(e);
     }
 }