80:40be5c189e2e | 81:5eb765a7a793 |
---|---|
2 using System.Collections.Generic; | 2 using System.Collections.Generic; |
3 using System.Linq; | 3 using System.Linq; |
4 using System.Text; | 4 using System.Text; |
5 using System.Threading; | 5 using System.Threading; |
6 using System.Threading.Tasks; | 6 using System.Threading.Tasks; |
7 using System.Windows; | |
7 | 8 |
8 namespace UI | 9 namespace UI |
9 { | 10 { |
10 public class Application | 11 public class Application |
11 { | 12 { |
15 | 16 |
16 private Thread thread; | 17 private Thread thread; |
17 private Queue<Action> queue = new Queue<Action>(); | 18 private Queue<Action> queue = new Queue<Action>(); |
18 private object sync = new object(); | 19 private object sync = new object(); |
19 private object result = new object(); | 20 private object result = new object(); |
21 private Boolean main = false; | |
20 | 22 |
21 private Boolean Running = false; | |
22 public String Name; | 23 public String Name; |
24 public List<Window> Windows = new List<Window>(); | |
25 public ApplicationMenu AppMenu = new ApplicationMenu(); | |
23 | 26 |
24 private Application() : base() | 27 private Application() : base() |
25 { | 28 { |
26 thread = new Thread(() => Run()); | 29 thread = new Thread(() => Run()); |
27 thread.SetApartmentState(ApartmentState.STA); | 30 thread.SetApartmentState(ApartmentState.STA); |
49 } | 52 } |
50 | 53 |
51 private void RunApplication() | 54 private void RunApplication() |
52 { | 55 { |
53 application = new System.Windows.Application(); | 56 application = new System.Windows.Application(); |
57 main = true; | |
54 application.Run(); | 58 application.Run(); |
55 } | 59 } |
56 | 60 |
57 public void Run() | 61 public void Run() |
58 { | 62 { |
64 Action action = queue.Dequeue(); | 68 Action action = queue.Dequeue(); |
65 action.Invoke(); | 69 action.Invoke(); |
66 lock (result) | 70 lock (result) |
67 { | 71 { |
68 Monitor.Pulse(result); | 72 Monitor.Pulse(result); |
73 } | |
74 if (main) | |
75 { | |
76 // end loop after shutdown | |
77 break; | |
69 } | 78 } |
70 } | 79 } |
71 } | 80 } |
72 } | 81 } |
73 | 82 |
114 { | 123 { |
115 Monitor.Wait(result); | 124 Monitor.Wait(result); |
116 } | 125 } |
117 } | 126 } |
118 } | 127 } |
128 | |
129 public void AddWindow(Window window) | |
130 { | |
131 Windows.Add(window); | |
132 } | |
133 | |
134 public void RemoveWindow(Window window) | |
135 { | |
136 Windows.Remove(window); | |
137 if (Windows.Count == 0) | |
138 { | |
139 application.Shutdown(); | |
140 } | |
141 } | |
119 } | 142 } |
120 | 143 |
121 public class ResultExec<T> | 144 public class ResultExec<T> |
122 { | 145 { |
123 public T Result; | 146 public T Result; |