Mercurial > pub > ImplabNet
comparison Implab.Fx/StaApartment.cs @ 211:3eb3255d8cc5 v2
Code review, added a non generic version of SyncContextPromise
author | cin |
---|---|
date | Tue, 21 Mar 2017 17:29:13 +0300 |
parents | 5dc21f6a3222 |
children | cbe10ac0731e |
comparison
equal
deleted
inserted
replaced
210:5dc21f6a3222 | 211:3eb3255d8cc5 |
---|---|
11 | 11 |
12 namespace Implab.Fx { | 12 namespace Implab.Fx { |
13 public class StaApartment : RunnableComponent { | 13 public class StaApartment : RunnableComponent { |
14 readonly Thread m_worker; | 14 readonly Thread m_worker; |
15 SynchronizationContext m_syncContext; | 15 SynchronizationContext m_syncContext; |
16 SyncContextPromise m_enterPromise; | |
17 | |
16 readonly Promise m_threadStarted; | 18 readonly Promise m_threadStarted; |
17 readonly Promise m_threadTerminated; | 19 readonly Promise m_threadTerminated; |
18 | 20 |
19 public StaApartment() : base(true) { | 21 public StaApartment() : base(true) { |
20 m_threadStarted = new Promise(); | 22 m_threadStarted = new Promise(); |
32 throw new InvalidOperationException(); | 34 throw new InvalidOperationException(); |
33 return m_syncContext; | 35 return m_syncContext; |
34 } | 36 } |
35 } | 37 } |
36 | 38 |
39 /// <summary> | |
40 /// Returns the promise which will dispatch all handlers inside the apartment using it's <see cref="SynchronizationContext"/> | |
41 /// </summary> | |
42 /// <remarks> | |
43 /// Current implementation is optimized and will lost aync operation stack | |
44 /// </remarks> | |
45 /// <returns>The promise</returns> | |
46 public IPromise Enter() { | |
47 if (m_enterPromise == null) | |
48 throw new InvalidOperationException(); | |
49 return m_enterPromise; | |
50 } | |
51 | |
37 public IPromise Invoke(Action<ICancellationToken> action) { | 52 public IPromise Invoke(Action<ICancellationToken> action) { |
38 Safe.ArgumentNotNull(action, "action"); | 53 Safe.ArgumentNotNull(action, "action"); |
39 | 54 |
40 if (m_syncContext == null) | 55 if (m_syncContext == null) |
41 throw new InvalidOperationException(); | 56 throw new InvalidOperationException(); |
154 } | 169 } |
155 | 170 |
156 void WorkerEntry() { | 171 void WorkerEntry() { |
157 m_syncContext = new WindowsFormsSynchronizationContext(); | 172 m_syncContext = new WindowsFormsSynchronizationContext(); |
158 SynchronizationContext.SetSynchronizationContext(m_syncContext); | 173 SynchronizationContext.SetSynchronizationContext(m_syncContext); |
159 | 174 m_enterPromise = new SyncContextPromise(m_syncContext); |
160 m_threadStarted.Resolve(); | 175 m_threadStarted.Resolve(); |
176 m_enterPromise.Resolve(); | |
161 | 177 |
162 Application.OleRequired(); | 178 Application.OleRequired(); |
163 Application.Run(); | 179 Application.Run(); |
164 | 180 |
165 try { | 181 try { |