Beispiel #1
0
        /// <summary>
        /// Starts a background task with the given parameter that runs on a parallel thread. Shall be called from the UI-thread.
        /// </summary>
        /// <param name="task">The starting method of the task.</param>
        /// <param name="name">The name of the executing thread of the task.</param>
        /// <param name="parameter">The starting parameter of the task.</param>
        /// <returns>A reference to the interface of the created task.</returns>
        public static IUIBackgroundTask StartParallelTask(UIParallelTaskMethod task, string name, object parameter)
        {
            if (uiThread != null && RCThread.CurrentThread != uiThread)
            {
                throw new InvalidOperationException("UITaskManager.StartParallelTask shall be called from the UI-thread!");
            }
            if (calledFromUi)
            {
                throw new InvalidOperationException("Recursive call on UITaskManager!");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            calledFromUi = true;
            uiThread     = RCThread.CurrentThread;
            RCThread       taskThread = new RCThread(ParallelTaskProc, name);
            UIParallelTask taskData   = new UIParallelTask(task, parameter);

            lock (runningParallelTasks)
            {
                runningParallelTasks.Add(taskThread, taskData);
            }

            taskThread.Start(taskData);
            calledFromUi = false;
            return(taskData);
        }
 /// <summary>
 /// Constructs a UIParallelTask instance.
 /// </summary>
 public UIParallelTask(UIParallelTaskMethod taskProc, object parameter)
 {
     this.taskProc       = taskProc;
     this.parameter      = parameter;
     this.postedMessages = new List <object>();
     this.postedFailure  = null;
     this.isFinished     = false;
 }
Beispiel #3
0
 /// <summary>
 /// Starts a background task that runs on a parallel thread. Shall be called from the UI-thread.
 /// </summary>
 /// <param name="task">The starting method of the task.</param>
 /// <param name="name">The name of the executing thread of the task.</param>
 /// <returns>A reference to the interface of the created task.</returns>
 public static IUIBackgroundTask StartParallelTask(UIParallelTaskMethod task, string name)
 {
     return(StartParallelTask(task, name, null));
 }