# HG changeset patch # User cin # Date 1490106553 -10800 # Node ID 3eb3255d8cc5fd3afe82cac44fc5fe7fda6d5fc8 # Parent 5dc21f6a32228c7cf5665e43b2b1ef637de288a2 Code review, added a non generic version of SyncContextPromise diff -r 5dc21f6a3222 -r 3eb3255d8cc5 Implab.Fx/StaApartment.cs --- a/Implab.Fx/StaApartment.cs Mon Mar 20 17:44:18 2017 +0300 +++ b/Implab.Fx/StaApartment.cs Tue Mar 21 17:29:13 2017 +0300 @@ -13,6 +13,8 @@ public class StaApartment : RunnableComponent { readonly Thread m_worker; SynchronizationContext m_syncContext; + SyncContextPromise m_enterPromise; + readonly Promise m_threadStarted; readonly Promise m_threadTerminated; @@ -34,6 +36,19 @@ } } + /// + /// Returns the promise which will dispatch all handlers inside the apartment using it's + /// + /// + /// Current implementation is optimized and will lost aync operation stack + /// + /// The promise + public IPromise Enter() { + if (m_enterPromise == null) + throw new InvalidOperationException(); + return m_enterPromise; + } + public IPromise Invoke(Action action) { Safe.ArgumentNotNull(action, "action"); @@ -156,8 +171,9 @@ void WorkerEntry() { m_syncContext = new WindowsFormsSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(m_syncContext); - + m_enterPromise = new SyncContextPromise(m_syncContext); m_threadStarted.Resolve(); + m_enterPromise.Resolve(); Application.OleRequired(); Application.Run(); diff -r 5dc21f6a3222 -r 3eb3255d8cc5 Implab/Implab.csproj --- a/Implab/Implab.csproj Mon Mar 20 17:44:18 2017 +0300 +++ b/Implab/Implab.csproj Tue Mar 21 17:29:13 2017 +0300 @@ -99,9 +99,10 @@ + - + diff -r 5dc21f6a3222 -r 3eb3255d8cc5 Implab/SyncContextPromise.cs --- a/Implab/SyncContextPromise.cs Mon Mar 20 17:44:18 2017 +0300 +++ b/Implab/SyncContextPromise.cs Tue Mar 21 17:29:13 2017 +0300 @@ -1,18 +1,21 @@ -using System.Threading; -using System; - -namespace Implab { - public class SyncContextPromise : Promise { - readonly SynchronizationContext m_context; - - public SyncContextPromise(SynchronizationContext context) { - Safe.ArgumentNotNull(context, "context"); - m_context = context; - } - - protected override void SignalHandler(HandlerDescriptor handler, int signal) { - m_context.Post(x => base.SignalHandler(handler, signal), null); - } - } -} - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; + +namespace Implab { + public class SyncContextPromise : Promise { + readonly SynchronizationContext m_context; + + public SyncContextPromise(SynchronizationContext context) { + Safe.ArgumentNotNull(context, "context"); + + m_context = context; + } + + protected override void SignalHandler(HandlerDescriptor handler, int signal) { + m_context.Post(x => base.SignalHandler(handler, signal), null); + } + } +} diff -r 5dc21f6a3222 -r 3eb3255d8cc5 Implab/SyncContextPromiseT.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab/SyncContextPromiseT.cs Tue Mar 21 17:29:13 2017 +0300 @@ -0,0 +1,18 @@ +using System.Threading; +using System; + +namespace Implab { + public class SyncContextPromise : Promise { + readonly SynchronizationContext m_context; + + public SyncContextPromise(SynchronizationContext context) { + Safe.ArgumentNotNull(context, "context"); + m_context = context; + } + + protected override void SignalHandler(HandlerDescriptor handler, int signal) { + m_context.Post(x => base.SignalHandler(handler, signal), null); + } + } +} +