Auto status change to "Under Review"
@@ -0,0 +1,18 | |||
|
1 | using System.Threading; | |
|
2 | using System; | |
|
3 | ||
|
4 | namespace Implab { | |
|
5 | public class SyncContextPromise<T> : Promise<T> { | |
|
6 | readonly SynchronizationContext m_context; | |
|
7 | ||
|
8 | public SyncContextPromise(SynchronizationContext context) { | |
|
9 | Safe.ArgumentNotNull(context, "context"); | |
|
10 | m_context = context; | |
|
11 | } | |
|
12 | ||
|
13 | protected override void SignalHandler(HandlerDescriptor handler, int signal) { | |
|
14 | m_context.Post(x => base.SignalHandler(handler, signal), null); | |
|
15 | } | |
|
16 | } | |
|
17 | } | |
|
18 |
@@ -13,6 +13,8 namespace Implab.Fx { | |||
|
13 | 13 | public class StaApartment : RunnableComponent { |
|
14 | 14 | readonly Thread m_worker; |
|
15 | 15 | SynchronizationContext m_syncContext; |
|
16 | SyncContextPromise m_enterPromise; | |
|
17 | ||
|
16 | 18 | readonly Promise m_threadStarted; |
|
17 | 19 | readonly Promise m_threadTerminated; |
|
18 | 20 | |
@@ -34,6 +36,19 namespace Implab.Fx { | |||
|
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 | 52 | public IPromise Invoke(Action<ICancellationToken> action) { |
|
38 | 53 | Safe.ArgumentNotNull(action, "action"); |
|
39 | 54 | |
@@ -156,8 +171,9 namespace Implab.Fx { | |||
|
156 | 171 | void WorkerEntry() { |
|
157 | 172 | m_syncContext = new WindowsFormsSynchronizationContext(); |
|
158 | 173 | SynchronizationContext.SetSynchronizationContext(m_syncContext); |
|
159 | ||
|
174 | m_enterPromise = new SyncContextPromise(m_syncContext); | |
|
160 | 175 | m_threadStarted.Resolve(); |
|
176 | m_enterPromise.Resolve(); | |
|
161 | 177 | |
|
162 | 178 | Application.OleRequired(); |
|
163 | 179 | Application.Run(); |
@@ -99,9 +99,10 | |||
|
99 | 99 | <Compile Include="Properties\AssemblyInfo.cs" /> |
|
100 | 100 | <Compile Include="Parallels\AsyncPool.cs" /> |
|
101 | 101 | <Compile Include="Safe.cs" /> |
|
102 | <Compile Include="SyncContextPromise.cs" /> | |
|
102 | 103 | <Compile Include="ValueEventArgs.cs" /> |
|
103 | 104 | <Compile Include="PromiseExtensions.cs" /> |
|
104 | <Compile Include="SyncContextPromise.cs" /> | |
|
105 | <Compile Include="SyncContextPromiseT.cs" /> | |
|
105 | 106 | <Compile Include="Diagnostics\OperationContext.cs" /> |
|
106 | 107 | <Compile Include="Diagnostics\TraceContext.cs" /> |
|
107 | 108 | <Compile Include="Diagnostics\LogEventArgs.cs" /> |
@@ -1,12 +1,16 | |||
|
1 |
using System |
|
|
2 | using System; | |
|
1 | using System; | |
|
2 | using System.Collections.Generic; | |
|
3 | using System.Linq; | |
|
4 | using System.Text; | |
|
5 | using System.Threading; | |
|
3 | 6 | |
|
4 | 7 | namespace Implab { |
|
5 |
public class SyncContextPromise |
|
|
8 | public class SyncContextPromise : Promise { | |
|
6 | 9 | readonly SynchronizationContext m_context; |
|
7 | 10 | |
|
8 | 11 | public SyncContextPromise(SynchronizationContext context) { |
|
9 | 12 | Safe.ArgumentNotNull(context, "context"); |
|
13 | ||
|
10 | 14 | m_context = context; |
|
11 | 15 | } |
|
12 | 16 | |
@@ -15,4 +19,3 namespace Implab { | |||
|
15 | 19 | } |
|
16 | 20 | } |
|
17 | 21 | } |
|
18 |
General Comments 3
ok, latest stable version should be in default
You need to be logged in to leave comments.
Login now