-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomPriceGenerator.cs
48 lines (44 loc) · 1.72 KB
/
RandomPriceGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Threading;
namespace StockDataVisualizer
{
/// <summary>
/// Class to generate prices
/// </summary>
public class RandomPriceGenerator
{
private StockPriceTickerUpdate updater = new StockPriceTickerUpdate();
private CancellationToken _token;
public RandomPriceGenerator(CancellationToken token)
{
this._token = token;
}
/// <summary>
/// Core method which starts the ticker by generating random inputs
/// </summary>
public void StartServer()
{
Logger.Instance.Log("Starting the ticker price updater");
for (; ;)
{
//_token.ThrowIfCancellationRequested();
if (_token.IsCancellationRequested)
break;
var evt = new StockPriceChangeEvent(
StockDataVisualizer.TickerSymbols[new Random().Next(0, StockDataVisualizer.TickerSymbols.Count)],
new Random().Next(1, 700),
new Random().Next(1, 750),
new Random().Next(1, 600),
new Random().Next(1, 650));
//:~ Deliberate attempt to slow down screen refresh interval
Thread.Sleep(150);
ThreadPool.QueueUserWorkItem(Parallellize, evt);
}
}
public void Parallellize(object evt)
{
var stockpriceChangeEvent = evt as StockPriceChangeEvent;
updater.OnChangeRaiseEvent(stockpriceChangeEvent);
}
}
}