internal static void ApplyDispatchBehavior(Type type, string threadName, DispatchRuntime dispatch) { Debug.Assert(dispatch.SynchronizationContext == null); if (m_Contexts.ContainsKey(type) == false) { m_Contexts[type] = new AffinitySynchronizer(threadName); } dispatch.SynchronizationContext = m_Contexts[type]; }
public void WithAffinitySynchronizer() { SynchronizationContext context = new AffinitySynchronizer("Test Thread"); SynchronizationContext.SetSynchronizationContext(context); Assert.IsNotNull(SynchronizationContext.Current); using (context as IDisposable) { IMyContract channel = InProcFactory.CreateChannel<MyService, IMyContract>(); Assert.AreEqual("Test Thread", channel.GetThreadName()); InProcFactory.CloseChannel<IMyContract>(channel); } }