public Task <int> Start() { return(Task <int> .Factory.StartNew(() => { SampleUtilities.DoCpuIntensiveOperation(2.0); return 42; })); }
MarketRecommendation CompareModels(IEnumerable <MarketModel> models) { SampleUtilities.DoCpuIntensiveOperation(2.0 * speedFactor, cts.Token); if (cts.Token.IsCancellationRequested) { return(null); } else { return(ModelComparer.Run(models.ToArray())); } }
/// <summary> /// Normalize stock data. /// </summary> StockDataCollection NormalizeData(StockDataCollection marketData) { SampleUtilities.DoCpuIntensiveOperation(2.0 * speedFactor, cts.Token); if (cts.Token.IsCancellationRequested) { return(null); } else { return(new StockDataCollection(marketData)); } }
MarketModel RunModel(StockAnalysisCollection data) { SampleUtilities.DoCpuIntensiveOperation(2.0 * speedFactor, cts.Token); if (cts.Token.IsCancellationRequested) { return(null); } else { return(MarketModeler.Run(data)); } }
static void Chapter6Example01ParallelWhileNotEmpty2(Tree <string> tree) { for (int i = 0; i < N; i++) { ConcurrentBag <string> result = new ConcurrentBag <string>(); Walk5(tree, (data) => { SampleUtilities.DoCpuIntensiveOperation(Time); result.Add(data); }); } }
static void Chapter6Example1Sequential(Tree <string> tree) { for (int i = 0; i < N; i++) { List <string> result = new List <string>(); SequentialWalk(tree, (data) => { SampleUtilities.DoCpuIntensiveOperation(Time); result.Add(data); }); } Console.WriteLine(); }
StockDataCollection MergeMarketData(IEnumerable <StockDataCollection> allMarketData) { SampleUtilities.DoCpuIntensiveOperation(2.0 * speedFactor, cts.Token); var securities = new List <StockData>(); if (!cts.Token.IsCancellationRequested) { foreach (StockDataCollection md in allMarketData) { securities.AddRange(md); } } if (cts.Token.IsCancellationRequested) { return(null); } else { return(new StockDataCollection(securities)); } }
/// <summary> /// A computationally intensive function /// </summary> static int F4(int value1, int value2) { SampleUtilities.DoCpuIntensiveOperation(0.1); return(value1 + value2); }
/// <summary> /// A computationally intensive function /// </summary> static int F3(int value) { SampleUtilities.DoCpuIntensiveOperation(1.0); return(value + 1); }
/// <summary> /// A computationally intensive function /// </summary> static int F1(int value) { SampleUtilities.DoCpuIntensiveOperation(2.0); return(value * value); }
static void SearchRight(CancellationToken token) { token.ThrowIfCancellationRequested(); SampleUtilities.DoCpuIntensiveOperation(TaskSeconds * .3, token); token.ThrowIfCancellationRequested(); }
static void DoCenter() { SampleUtilities.DoCpuIntensiveOperation(TaskSeconds * .2); }
static void DoRight() { SampleUtilities.DoCpuIntensiveOperation(TaskSeconds * .3); }
static void Stage4AdditionalWork() { SampleUtilities.DoCpuIntensiveOperation(StageTime[3]); }
static void Stage3AdditionalWork() { SampleUtilities.DoCpuIntensiveOperation(StageTime[2] / Phrases.Length); }