/// <summary> /// Gets a TaskThread object of the role supplied. /// </summary> /// <param name="role">The role of the TaskThread.</param> /// <returns>The first instance matching the supplied role.</returns> public static TaskThread GetTaskThread(ThreadRole role) { return(TaskThreads.Find(new Predicate <TaskThread>(delegate(TaskThread tr) { if (tr.Role == role) { return true; } return false; }))); }
/// <summary> /// Runs the task on a new thread. /// </summary> /// <param name="t">The Task to run.</param> /// <param name="r">The ThreadRole to be used.</param> /// <param name="delayLen">The time to wait, in ms, until the task is run.</param> public static void AddAsyncTask(Task t, ThreadRole r = ThreadRole.Standard, int delayLen = 1000) { switch (r) { case ThreadRole.Standard: TaskQueue.Enqueue(t); break; case ThreadRole.Important: ImportantTaskQueue.Enqueue(t); break; case ThreadRole.Delayed: DelayedTasks.Add(t, delayLen); break; } if (GetTaskThread(r) == null || GetTaskThread(r).Thread == null) { SpawnTaskThread(r); } }
/// <summary> /// Spawns a new task thread and adds it to the list of threads. /// </summary> /// <param name="role">The role of the thread.</param> public static void SpawnTaskThread(ThreadRole role) { TaskThread t; switch (role) //Set properties. { case ThreadRole.Delayed: t = TaskThread.SpawnTaskThread(role, ManageTaskDelayThread, TaskThreads.Count + 1, true); break; case ThreadRole.Important: t = TaskThread.SpawnTaskThread(role, ManageImportantTaskThread, TaskThreads.Count + 1, false); break; default: case ThreadRole.Standard: t = TaskThread.SpawnTaskThread(role, ManageTaskThread, TaskThreads.Count + 1, true); break; } TaskThreads.Add(t); t.Start(); //Start the new thread. }
public static TaskThread SpawnTaskThread(ThreadRole Role, ThreadStart Void, int ID, bool IsBackground) { return new TaskThread { Role = Role, ThreadDelegate = Void, ThreadID = ID, Background = IsBackground }; }
public static TaskThread SpawnTaskThread(ThreadRole Role, ThreadStart Void, int ID, bool IsBackground) { return(new TaskThread { Role = Role, ThreadDelegate = Void, ThreadID = ID, Background = IsBackground }); }
/// <summary> /// Stops a task thread assocated with the givin role. /// </summary> /// <param name="role">The role of the thread to kill.</param> /// <returns>Whether the thread was killed or not.</returns> public static bool KillTaskThread(ThreadRole role) { TaskThread t = GetTaskThread(role); return(KillTaskThread(t)); }
/// <summary> /// Gets a TaskThread object of the role supplied. /// </summary> /// <param name="role">The role of the TaskThread.</param> /// <returns>The first instance matching the supplied role.</returns> public static TaskThread GetTaskThread(ThreadRole role) { return TaskThreads.Find(new Predicate<TaskThread>(delegate(TaskThread tr) { if (tr.Role == role) return true; return false; })); }
/// <summary> /// Stops a task thread assocated with the givin role. /// </summary> /// <param name="role">The role of the thread to kill.</param> /// <returns>Whether the thread was killed or not.</returns> public static bool KillTaskThread(ThreadRole role) { TaskThread t = GetTaskThread(role); return KillTaskThread(t); }