Mercurial > silverbladetech
comparison MetroWpf/FxRates.Service/PricingService.cs @ 24:a8b50a087544
Stocks and FxRates working, new menu introduced. Working nicely so far
author | adminsh@apollo |
---|---|
date | Tue, 20 Mar 2012 20:18:35 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
23:399398841fd0 | 24:a8b50a087544 |
---|---|
1 using System; | |
2 using System.Threading; | |
3 using System.Threading.Tasks; | |
4 using FxRates.Common; | |
5 using System.Collections.Generic; | |
6 | |
7 namespace FxRates.Service | |
8 { | |
9 public class PricingService : IPricingService | |
10 { | |
11 PriceFactory factory; | |
12 bool _isRunning = false; | |
13 public bool IsRunning { get { return _isRunning; } } | |
14 | |
15 public PricingService() | |
16 { | |
17 factory = new PriceFactory(); | |
18 } | |
19 | |
20 public void Start() | |
21 { | |
22 Task.Factory.StartNew(() => | |
23 { | |
24 _isRunning = true; | |
25 while (_isRunning) | |
26 { | |
27 Thread.Sleep(10); | |
28 if (PriceUpdate == null) continue; | |
29 var latestPrice = factory.GetNextPrice(); | |
30 PriceUpdate(null, new PriceUpdateEventArgs { LatestPrice = latestPrice }); | |
31 } | |
32 }); | |
33 } | |
34 | |
35 public void Stop() | |
36 { | |
37 _isRunning = false; | |
38 } | |
39 | |
40 public List<FxRate> GetFullCurrentPrices() | |
41 { | |
42 return factory.CurrentPrices; | |
43 } | |
44 | |
45 public event EventHandler<PriceUpdateEventArgs> PriceUpdate; | |
46 } | |
47 } |