File tree Expand file tree Collapse file tree 3 files changed +46
-7
lines changed Expand file tree Collapse file tree 3 files changed +46
-7
lines changed Original file line number Diff line number Diff line change @@ -240,19 +240,16 @@ private string ActiveTime(PriceEntryBase priceEntry)
240
240
return time . FormatTime ( ) ;
241
241
}
242
242
243
+ SlidingBuffer < string > _consoleBuffer = new SlidingBuffer < string > ( 200 ) ;
244
+
243
245
private void WriteConsole ( string text )
244
246
{
245
247
Invoke ( new MethodInvoker (
246
248
delegate
247
249
{
248
- textConsole . AppendText ( text + Environment . NewLine ) ;
249
- int numOfLines = textConsole . Lines . Length - 200 ;
250
- if ( numOfLines <= 0 ) return ;
251
-
252
- var lines = textConsole . Lines ;
253
- var newLines = lines . Skip ( numOfLines ) ;
250
+ _consoleBuffer . Add ( text ) ;
254
251
255
- textConsole . Lines = newLines . ToArray ( ) ;
252
+ textConsole . Lines = _consoleBuffer . ToArray ( ) ;
256
253
textConsole . Focus ( ) ;
257
254
textConsole . SelectionStart = textConsole . Text . Length ;
258
255
textConsole . SelectionLength = 0 ;
Original file line number Diff line number Diff line change 84
84
<Compile Include =" Services\WestHashService.cs" />
85
85
<Compile Include =" PriceEntries\YaampPriceEntry.cs" />
86
86
<Compile Include =" Services\YaampService.cs" />
87
+ <Compile Include =" Utility\SlidingBuffer.cs" />
87
88
<Compile Include =" Utility\SortableBindingList.cs" />
88
89
<Compile Include =" Utility\PropertyChangedBase.cs" />
89
90
<Compile Include =" Utility\WebUtil.cs" />
Original file line number Diff line number Diff line change
1
+ using System . Collections ;
2
+ using System . Collections . Generic ;
3
+
4
+ namespace MinerControl . Utility
5
+ {
6
+ // Taken from http://stackoverflow.com/questions/6392516
7
+
8
+ public class SlidingBuffer < T > : IEnumerable < T >
9
+ {
10
+ private readonly Queue < T > _queue ;
11
+ private readonly int _maxCount ;
12
+
13
+ public SlidingBuffer ( int maxCount )
14
+ {
15
+ _maxCount = maxCount ;
16
+ _queue = new Queue < T > ( maxCount ) ;
17
+ }
18
+
19
+ public void Add ( T item )
20
+ {
21
+ if ( _queue . Count == _maxCount )
22
+ _queue . Dequeue ( ) ;
23
+ _queue . Enqueue ( item ) ;
24
+ }
25
+
26
+ public IEnumerator < T > GetEnumerator ( )
27
+ {
28
+ return _queue . GetEnumerator ( ) ;
29
+ }
30
+
31
+ IEnumerator IEnumerable . GetEnumerator ( )
32
+ {
33
+ return GetEnumerator ( ) ;
34
+ }
35
+
36
+ public int Count
37
+ {
38
+ get { return _queue . Count ; }
39
+ }
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments