-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathProgram.cs
88 lines (67 loc) · 1.74 KB
/
Program.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using ReactiveUI;
using Terminal.Gui;
namespace SmartImage.UI2
{
public static class Program
{
public class TerminalScheduler : LocalScheduler
{
public static readonly TerminalScheduler Default = new();
private TerminalScheduler() { }
public override IDisposable Schedule<TState>(
TState state,
TimeSpan dueTime,
Func<IScheduler, TState, IDisposable> action
)
{
IDisposable PostOnMainLoop()
{
var composite = new CompositeDisposable(2);
var cancellation = new CancellationDisposable();
Application.MainLoop.Invoke(
() =>
{
if (!cancellation.Token.IsCancellationRequested) {
composite.Add(action(this, state));
}
}
);
composite.Add(cancellation);
return composite;
}
IDisposable PostOnMainLoopAsTimeout()
{
var composite = new CompositeDisposable(2);
object timeout = Application.MainLoop.AddTimeout(
dueTime, (cb) =>
{
composite.Add(action(this, state));
return false;
}
);
composite.Add(Disposable.Create(() => Application.MainLoop.RemoveTimeout(timeout)));
return composite;
}
return dueTime == TimeSpan.Zero
? PostOnMainLoop()
: PostOnMainLoopAsTimeout();
}
}
public class Item1 { }
public static void Main(string[] args)
{
Application.Init();
RxApp.MainThreadScheduler = Program.TerminalScheduler.Default;
RxApp.TaskpoolScheduler = TaskPoolScheduler.Default;
var tx = new TextField();
var tv = new TreeView<Item1>();
var w = new Window();
w.Add(tv);
Application.Run(w);
Application.Top.Dispose();
Application.Shutdown();
}
}
}