本文整理汇总了C#中System.Threading.Tasks.TaskScheduler类的典型用法代码示例。如果您正苦于以下问题:C# TaskScheduler类的具体用法?C# TaskScheduler怎么用?C# TaskScheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TaskScheduler类属于System.Threading.Tasks命名空间,在下文中一共展示了TaskScheduler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:PaulNorth,项目名称:orleans,代码行数:27,代码来源:QueuedTaskSchedulerTests_Set1.cs
示例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;
}
开发者ID:akondrahman,项目名称:SrcML.NET,代码行数:17,代码来源:SourceMonitor.cs
示例3: AbstractIndexingExecuter
protected AbstractIndexingExecuter(
ITransactionalStorage transactionalStorage, WorkContext context, TaskScheduler scheduler)
{
this.transactionalStorage = transactionalStorage;
this.context = context;
this.scheduler = scheduler;
}
开发者ID:shiranGinige,项目名称:ravendb,代码行数:7,代码来源:AbstractIndexingExecuter.cs
示例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);
}
开发者ID:Trojka,项目名称:monoCPVanity,代码行数:7,代码来源:CodeProjectMemberReputationViewModel.cs
示例5: ImageProcessor
public ImageProcessor(StateColor setState, ShowState showState, TaskScheduler guiContext, Logger log)
{
_setState = setState;
_showState = showState;
GuiContext = guiContext;
_logger = log;
}
开发者ID:fire-eggs,项目名称:PHASH,代码行数:7,代码来源:ImageProcessor.cs
示例6: CommandsControl
public CommandsControl()
{
InitializeComponent();
if (!Program.Running) return;
Scheduler = TaskScheduler.FromCurrentSynchronizationContext();
CommandsManager.CommandsController = this;
}
开发者ID:hesa2020,项目名称:Hesa-Twitch-Bot,代码行数:7,代码来源:CommandsControl.cs
示例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 ();
});
}
开发者ID:praeclarum,项目名称:Continuous,代码行数:30,代码来源:HttpServer.cs
示例8: MockSampleListWorker
public MockSampleListWorker()
{
// for GUI synchronized operations
mScheduler = TaskScheduler.FromCurrentSynchronizationContext();
// for the remote access example
RemotePluginService.StartService();
}
开发者ID:PatrickKursawe,项目名称:ChronosMockPlugin,代码行数:7,代码来源:MockSampleListWorker.cs
示例9: PluginController
public PluginController(IUnityContainer container, ErrorHandlingService errorHandlingService)
{
_container = container;
_errorHandlingService = errorHandlingService;
_scheduler = TaskScheduler.FromCurrentSynchronizationContext();
LoadedPlugins = new ObservableCollection<Plugin>();
}
开发者ID:2594636985,项目名称:BaktunShell,代码行数:7,代码来源:PluginController.cs
示例10: WorldViewModel
public WorldViewModel()
{
_uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
_uiFactory = new TaskFactory(_uiScheduler);
Tools = new OrderingCollection<ITool, IOrderMetadata>(t => t.Metadata.Order);
CompositionTarget.Rendering += CompTargetRender;
}
开发者ID:hamadx99,项目名称:Terraria-Map-Editor,代码行数:7,代码来源:WorldViewModel.cs
示例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;
}
开发者ID:bevacqua,项目名称:Swarm,代码行数:32,代码来源:VirtualUserNetwork.cs
示例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);
}
开发者ID:romerod,项目名称:Testeroids,代码行数:11,代码来源:TplTestPlatformHelper.cs
示例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();
}
开发者ID:mkloubert,项目名称:Extensions.NET,代码行数:69,代码来源:Tasks.StartAll.cs
示例14: DeadPeerDetectorEntry
public DeadPeerDetectorEntry(PeerDescriptor descriptor, IDirectoryConfiguration configuration, IBus bus, TaskScheduler taskScheduler)
{
Descriptor = descriptor;
_configuration = configuration;
_bus = bus;
_taskScheduler = taskScheduler;
}
开发者ID:rbouallou,项目名称:Zebus.Directory,代码行数:7,代码来源:DeadPeerDetectorEntry.cs
示例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);
}
}
}
开发者ID:bijakatlykkex,项目名称:NBitcoin.Indexer,代码行数:35,代码来源:ExponentialBackoff.cs
示例16: NotifyTaskCompletion
/// <summary>
/// Initializes a task notifier watching the specified task.
/// </summary>
/// <param name="task">
/// The task to watch.
/// </param>
/// <param name="scheduler">
/// The task scheduler that should be used.
/// </param>
public NotifyTaskCompletion(Task task, TaskScheduler scheduler)
{
_task = task;
if (task.IsCompleted)
{
return;
}
_taskCompleted = task.ContinueWith(t =>
{
NotifyPropertyChanged(() => Status);
NotifyPropertyChanged(() => IsCompleted);
NotifyPropertyChanged(() => IsNotCompleted);
if (t.IsCanceled)
{
NotifyPropertyChanged(() => IsCanceled);
}
else if (t.IsFaulted)
{
NotifyPropertyChanged(() => IsFaulted);
NotifyPropertyChanged(() => Exception);
NotifyPropertyChanged(() => InnerException);
NotifyPropertyChanged(() => ErrorMessage);
}
else
{
NotifyPropertyChanged(() => IsSuccessfullyCompleted);
}
}, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, scheduler);
}
开发者ID:jprofi,项目名称:MSProjects,代码行数:40,代码来源:NotifyTaskCompletion.cs
示例17: ViewOrders
public ViewOrders()
{
InitializeComponent();
this.scheduler = TaskScheduler.FromCurrentSynchronizationContext();
te = new ThirtyOneEntities();
}
开发者ID:eclipsed4utoo,项目名称:ThirtyOne,代码行数:7,代码来源:ViewOrders.xaml.cs
示例18: DatabaseView
public DatabaseView(string connStr)
{
InitializeComponent();
this.db = new Database(connStr);
currentContext = TaskScheduler.FromCurrentSynchronizationContext();
InitAsync();
}
开发者ID:OryxAwakening,项目名称:Fabiano_Swagger_of_Doom,代码行数:7,代码来源:DatabaseView.cs
示例19: Initialize
// This static initialization method *must* be invoked on the UI thread to ensure that the static 'foregroundThread' field is correctly initialized.
public static ForegroundThreadAffinitizedObject Initialize(bool force = false)
{
if (s_foregroundThread != null && !force)
{
return new ForegroundThreadAffinitizedObject();
}
s_foregroundThread = Thread.CurrentThread;
var previousContext = SynchronizationContext.Current;
try
{
// None of the work posted to the foregroundTaskScheduler should block pending keyboard/mouse input from the user.
// So instead of using the default priority which is above user input, we use Background priority which is 1 level
// below user input.
SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher, DispatcherPriority.Background));
s_foregroundTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
}
finally
{
SynchronizationContext.SetSynchronizationContext(previousContext);
}
return new ForegroundThreadAffinitizedObject();
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:26,代码来源:ForegroundThreadAffinitizedObject.cs
示例20: SrcMLProject
/// <summary>
/// Creates a new project object
/// </summary>
/// <param name="scheduler">The task scheduler</param>
/// <param name="monitor">The file monitor</param>
///<param name="generator">The SrcML generator to use</param>
public SrcMLProject(TaskScheduler scheduler, AbstractFileMonitor monitor, SrcMLGenerator generator) {
Scheduler = scheduler;
Monitor = monitor;
SetupMonitor(generator);
SourceArchive.Generator.IsLoggingErrors = true;
SourceArchive.Generator.ErrorLog = new StreamWriter(Path.Combine(StoragePath, "error.log"), false);
}
开发者ID:akondrahman,项目名称:SrcML.NET,代码行数:13,代码来源:SrcMLProject.cs
注:本文中的System.Threading.Tasks.TaskScheduler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论