本文整理汇总了C#中System.Threading.Task.Schedule方法的典型用法代码示例。如果您正苦于以下问题:C# Task.Schedule方法的具体用法?C# Task.Schedule怎么用?C# Task.Schedule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Task
的用法示例。
在下文中一共展示了Task.Schedule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public void Add (Task task)
{
if (task == null)
return;
if (task.Source == null)
throw new Exception ("Attempting to add Task with no source!");
Task old_task = null;
lock (big_lock) {
// Keep track of when immediate priority tasks are
// added so that we can throttle if the scheduler
// is being slammed with them.
if (task.Priority == Priority.Immediate) {
// Shift our times down by one
Array.Copy (last_immediate_times, 1, last_immediate_times, 0, immediate_throttle_count - 1);
last_immediate_times [immediate_throttle_count - 1] = DateTime.Now;
}
old_task = tasks_by_tag [task.Tag] as Task;
task.Schedule (this);
// Re-adding the same task is basically a no-op --- we
// just update the timestamp and return.
if (old_task == task)
return;
if (Debug) {
Logger.Log.Debug ("Adding task {0}", task.Tag);
if (task.Description != null)
Logger.Log.Debug (" Desc: {0}", task.Description);
}
if (task.Priority == Priority.Shutdown)
shutdown_task_queue.Enqueue (task);
else
tasks_by_tag [task.Tag] = task;
Monitor.Pulse (big_lock);
}
// If we clobbered another task, call cancel on it.
// This happens after we release the lock, since
// cancellation could result in a task group post-hook
// being run.
if (old_task != null)
old_task.Cancel ();
}