-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
63 lines (51 loc) · 2.86 KB
/
Copy pathProgram.cs
File metadata and controls
63 lines (51 loc) · 2.86 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using DynamicData;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
namespace ExpireAfterLeak;
internal class Program
{
static void Main(string[] args)
{
var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
Console.WriteLine("Started");
var subscription = Observable.Interval(TimeSpan.FromMilliseconds(250))
.Select(x => new Item(x % 100))
.Do(x => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} Creating Item with value {x.Value}"))
.Take(5)
//.Do(x => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} {stopwatch.ElapsedMilliseconds:D6} {string.Join('\n', x)}"), ex => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} {ex}"), () => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} Source Completed"))
//.ToObservableChangeSet(x => x.Value, expireAfter: _ => TimeSpan.FromSeconds(10), scheduler: NewThreadScheduler.Default)
//.ToObservableChangeSet(x => x.Value, scheduler: NewThreadScheduler.Default)
//.Do(x => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} {string.Join('\n', x)}"), ex => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} {ex}"), () => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} Source Completed"))
//.ExpireAfter(_ => TimeSpan.FromSeconds(10), pollingInterval: TimeSpan.FromSeconds(5), scheduler: NewThreadScheduler.Default)
.ToObservableChangeSet(x => x.Value, scheduler: NewThreadScheduler.Default)
.Do(x => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} {string.Join('\n', x)}"), ex => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} {ex}"), () => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} Source Completed"))
.ExpireAfter(_ => TimeSpan.FromSeconds(10), scheduler: NewThreadScheduler.Default)
.Subscribe(x => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} {string.Join('\n', x)}"), ex => Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} {ex}"), () =>
{
Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} Subscribe Completed");
GC.Collect();
});
Console.ReadLine();
Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} Dispose");
subscription.Dispose();
while (!Console.KeyAvailable)
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} GC.Collect");
Thread.Sleep(1000);
}
Console.WriteLine($"{stopwatch.ElapsedMilliseconds:D6} Exit");
}
}
internal class Item
{
public long Value { get; }
public Item(long v) => Value = v;
~Item()
{
Console.WriteLine($"Item with value {Value} is being finalized.");
}
}