本文整理汇总了C#中System.Threading.Tasks.TaskScheduler类的典型用法代码示例。如果您正苦于以下问题:C# TaskScheduler类的具体用法?C# TaskScheduler怎么用?C# TaskScheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TaskScheduler类属于System.Threading.Tasks命名空间,在下文中一共展示了TaskScheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunTestLoop
private void RunTestLoop(int numberOfTasks, TaskScheduler[] schedulers)
{
var taskList = new List<Task>(numberOfTasks);
for (int i = 0; i < numberOfTasks; i++)
{
int id = i; // capture
Task t = new Task(() =>
{
if (Verbose) output.WriteLine("Task: " + id);
});
if (schedulers == null || schedulers.Length == 0)
{
t.Start();
}
else
{
var scheduler = schedulers[i % schedulers.Length];
t.Start(scheduler);
}
taskList.Add(t);
}
Task.WaitAll(taskList.ToArray());
}
示例2: SourceMonitor
/// <summary>
/// Creates a new source monitor
/// </summary>
/// <param name="solution">The solution to monitor</param>
/// <param name="foldersToMonitor">A list of folders to monitor</param>
/// <param name="scanInterval">The interval at which to scan the folders (in
/// seconds) </param>
/// <param name="baseDirectory">The base directory for this monitor</param>
/// <param name="defaultArchive">The default archive to route files to</param>
/// <param name="otherArchives">Other archives to route files to</param>
public SourceMonitor(Solution solution, double scanInterval, TaskScheduler scheduler, string baseDirectory, AbstractArchive defaultArchive, SrcMLArchive sourceArchive, params AbstractArchive[] otherArchives)
: base(DirectoryScanningMonitor.MONITOR_LIST_FILENAME, scanInterval, scheduler, baseDirectory, defaultArchive, otherArchives) {
if(null != sourceArchive) {
RegisterArchive(sourceArchive, false);
}
this.MonitoredSolution = solution;
}
示例3: AbstractIndexingExecuter
protected AbstractIndexingExecuter(
ITransactionalStorage transactionalStorage, WorkContext context, TaskScheduler scheduler)
{
this.transactionalStorage = transactionalStorage;
this.context = context;
this.scheduler = scheduler;
}
示例4: LoadMemberReputation
public void LoadMemberReputation(TaskScheduler uiContext) {
WebImageRetriever imageDownloader = new WebImageRetriever ();
Task<byte[]> loadGraphTask = imageDownloader.GetImageStreamAsync (new Uri (MemberReputationGraphUrl));
loadGraphTask.ContinueWith (t => ReputationGraphLoaded(t.Result), uiContext);
}
示例5: ImageProcessor
public ImageProcessor(StateColor setState, ShowState showState, TaskScheduler guiContext, Logger log)
{
_setState = setState;
_showState = showState;
GuiContext = guiContext;
_logger = log;
}
示例6: CommandsControl
public CommandsControl()
{
InitializeComponent();
if (!Program.Running) return;
Scheduler = TaskScheduler.FromCurrentSynchronizationContext();
CommandsManager.CommandsController = this;
}
示例7: Run
public void Run ()
{
mainScheduler = TaskScheduler.FromCurrentSynchronizationContext ();
Task.Run (() => {
var url = "http://+:" + port + "/";
var remTries = 2;
while (remTries > 0) {
remTries--;
listener = new HttpListener ();
listener.Prefixes.Add (url);
try {
listener.Start ();
remTries = 0;
} catch (HttpListenerException ex) {
if (remTries == 1 && ex.ErrorCode == 5) { // Access Denied
GrantServerPermission (url);
} else {
throw;
}
}
}
Loop ();
});
}
示例8: MockSampleListWorker
public MockSampleListWorker()
{
// for GUI synchronized operations
mScheduler = TaskScheduler.FromCurrentSynchronizationContext();
// for the remote access example
RemotePluginService.StartService();
}
示例9: PluginController
public PluginController(IUnityContainer container, ErrorHandlingService errorHandlingService)
{
_container = container;
_errorHandlingService = errorHandlingService;
_scheduler = TaskScheduler.FromCurrentSynchronizationContext();
LoadedPlugins = new ObservableCollection<Plugin>();
}
示例10: WorldViewModel
public WorldViewModel()
{
_uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
_uiFactory = new TaskFactory(_uiScheduler);
Tools = new OrderingCollection<ITool, IOrderMetadata>(t => t.Metadata.Order);
CompositionTarget.Rendering += CompTargetRender;
}
示例11: VirtualUserNetwork
public VirtualUserNetwork(RequestCommand command)
{
if (command == null)
{
throw new ArgumentNullException("command");
}
if (command.Requests == null || command.Requests.Count == 0)
{
throw new ArgumentOutOfRangeException("command", Arguments.VirtualUserNetwork_EmptyCommandRequests);
}
if (command.Users == null)
{
throw new ArgumentNullException("command.Users");
}
if (command.Users.Amount < 1)
{
throw new ArgumentOutOfRangeException("command.Users.Amount", Arguments.VirtualUserNetwork_AmountNotGreaterThanZero);
}
ExecutionId = command.ExecutionId;
Guid = Guid.NewGuid();
Id = Guid.ToString().Split('-').First().ToUpper();
userSettings = command.Users;
taskScheduler = new WorkStealingTaskScheduler(userSettings.Amount);
tokenSource = new CancellationTokenSource();
queue = new ConcurrentQueue<IRestRequest>(command.Requests);
users = new ConcurrentBag<VirtualUser>();
RestClient = command.Client;
SleepTime = command.Users.SleepTime;
}
示例12: SetDefaultScheduler
/// <summary>
/// Uses reflection to set the default scheduler to use for any newly started task.
/// </summary>
/// <param name="taskScheduler">The <see cref="TaskScheduler"/> to use by default.</param>
public static void SetDefaultScheduler(TaskScheduler taskScheduler)
{
var taskSchedulerType = typeof(TaskScheduler);
var defaultTaskSchedulerField = taskSchedulerType.GetField("s_defaultTaskScheduler", BindingFlags.SetField | BindingFlags.Static | BindingFlags.NonPublic);
Debug.Assert(defaultTaskSchedulerField != null, "Could not find the TaskScheduler.s_defaultTaskScheduler field. We are assuming this implementation aspect of the .NET Framework to be able to unit test TPL.");
defaultTaskSchedulerField.SetValue(null, taskScheduler);
}
示例13: StartAll
/// <summary>
/// Starts a list of tasks.
/// </summary>
/// <param name="tasks">The tasks to start.</param>
/// <param name="exceptions">The variable where to write the occurred exceptions to.</param>
/// <param name="scheduler">The custom scheduler to use.</param>
/// <returns>
/// The started tasks or <see langword="null" /> if <paramref name="tasks" /> is also <see langword="null" />.
/// </returns>
public static Task[] StartAll(
this IEnumerable<Task> tasks,
out AggregateException exceptions,
TaskScheduler scheduler = null)
{
exceptions = null;
if (tasks == null)
{
return null;
}
var occurredExceptions = new List<Exception>();
var startedTasks = new List<Task>();
try
{
using (var e = tasks.GetEnumerator())
{
while (e.MoveNext())
{
try
{
var t = e.Current;
if (t == null)
{
continue;
}
if (scheduler == null)
{
t.Start();
}
else
{
t.Start(scheduler);
}
startedTasks.Add(t);
}
catch (Exception ex)
{
occurredExceptions.Add(ex);
}
}
}
}
catch (Exception ex)
{
occurredExceptions.Add(ex);
}
if (occurredExceptions.Count > 0)
{
exceptions = new AggregateException(occurredExceptions);
}
return startedTasks.ToArray();
}
示例14: DeadPeerDetectorEntry
public DeadPeerDetectorEntry(PeerDescriptor descriptor, IDirectoryConfiguration configuration, IBus bus, TaskScheduler taskScheduler)
{
Descriptor = descriptor;
_configuration = configuration;
_bus = bus;
_taskScheduler = taskScheduler;
}
示例15: Do
public async Task Do(Action act, TaskScheduler scheduler = null)
{
Exception lastException = null;
int retryCount = -1;
TimeSpan wait;
while (true)
{
try
{
var task = new Task(act);
task.Start(scheduler);
await task.ConfigureAwait(false);
break;
}
catch (OutOfMemoryException)
{
throw;
}
catch (Exception ex)
{
lastException = ex;
}
retryCount++;
if (!GetShouldRetry(retryCount, lastException, out wait))
{
ExceptionDispatchInfo.Capture(lastException).Throw();
}
else
{
await Task.Delay(wait).ConfigureAwait(false);
}
}
}