當前位置: 首頁>>代碼示例>>C#>>正文


C# Tasks.TaskScheduler類代碼示例

本文整理匯總了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());
        }
開發者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


注:本文中的System.Threading.Tasks.TaskScheduler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。