Esempio n. 1
0
 public Task <int> Start()
 {
     return(Task <int> .Factory.StartNew(() =>
     {
         SampleUtilities.DoCpuIntensiveOperation(2.0);
         return 42;
     }));
 }
Esempio n. 2
0
 MarketRecommendation CompareModels(IEnumerable <MarketModel> models)
 {
     SampleUtilities.DoCpuIntensiveOperation(2.0 * speedFactor, cts.Token);
     if (cts.Token.IsCancellationRequested)
     {
         return(null);
     }
     else
     {
         return(ModelComparer.Run(models.ToArray()));
     }
 }
Esempio n. 3
0
 /// <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));
     }
 }
Esempio n. 4
0
 MarketModel RunModel(StockAnalysisCollection data)
 {
     SampleUtilities.DoCpuIntensiveOperation(2.0 * speedFactor, cts.Token);
     if (cts.Token.IsCancellationRequested)
     {
         return(null);
     }
     else
     {
         return(MarketModeler.Run(data));
     }
 }
Esempio n. 5
0
 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);
         });
     }
 }
Esempio n. 6
0
 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();
 }
Esempio n. 7
0
        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));
            }
        }
Esempio n. 8
0
 /// <summary>
 /// A computationally intensive function
 /// </summary>
 static int F4(int value1, int value2)
 {
     SampleUtilities.DoCpuIntensiveOperation(0.1);
     return(value1 + value2);
 }
Esempio n. 9
0
 /// <summary>
 /// A computationally intensive function
 /// </summary>
 static int F3(int value)
 {
     SampleUtilities.DoCpuIntensiveOperation(1.0);
     return(value + 1);
 }
Esempio n. 10
0
 /// <summary>
 /// A computationally intensive function
 /// </summary>
 static int F1(int value)
 {
     SampleUtilities.DoCpuIntensiveOperation(2.0);
     return(value * value);
 }
Esempio n. 11
0
 static void SearchRight(CancellationToken token)
 {
     token.ThrowIfCancellationRequested();
     SampleUtilities.DoCpuIntensiveOperation(TaskSeconds * .3, token);
     token.ThrowIfCancellationRequested();
 }
Esempio n. 12
0
 static void DoCenter()
 {
     SampleUtilities.DoCpuIntensiveOperation(TaskSeconds * .2);
 }
Esempio n. 13
0
 static void DoRight()
 {
     SampleUtilities.DoCpuIntensiveOperation(TaskSeconds * .3);
 }
Esempio n. 14
0
 static void Stage4AdditionalWork()
 {
     SampleUtilities.DoCpuIntensiveOperation(StageTime[3]);
 }
Esempio n. 15
0
 static void Stage3AdditionalWork()
 {
     SampleUtilities.DoCpuIntensiveOperation(StageTime[2] / Phrases.Length);
 }