Example #1
0
        /// <summary>
        /// Posts a message back to the UI-thread. Shall not be called from the UI-thread in case of parallel tasks.
        /// </summary>
        /// <param name="message">The message to post.</param>
        public static void PostMessage(object message)
        {
            if (uiThread == null)
            {
                throw new InvalidOperationException("UITaskManager.PostMessage shall not be called before calling UITaskManager.StartParallelTask, UITaskManager.StartTimeSharingTask or UITaskManager.OnUpdate!");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (uiThread == RCThread.CurrentThread)
            {
                /// Call from a time sharing task
                if (scheduledTask == null)
                {
                    throw new InvalidOperationException("UITaskManager.PostMessage can be called from the UI-thread only if a time sharing task has been scheduled!");
                }
                scheduledTask.PostMessage(message);
            }
            else
            {
                /// Call from a parallel task.
                lock (runningParallelTasks)
                {
                    UIParallelTask task = runningParallelTasks[RCThread.CurrentThread];
                    task.PostMessage(message);
                }
            }
        }