Ejemplo n.º 1
0
        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];
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  Can only call before openning the host
        /// </summary>
        public void SetThreadAffinity(string threadName)
        {
            if (State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Host is already opened");
            }

            Debug.Assert(m_AffinitySynchronizer == null);//Can call only once

            m_AffinitySynchronizer = new AffinitySynchronizer(threadName);
            SynchronizationContext.SetSynchronizationContext(m_AffinitySynchronizer);
        }
Ejemplo n.º 3
0
      /// <summary>
      /// Can only call before openning the host
      /// </summary>
      public static void SetThreadAffinity(this ServiceHost host,string threadName)
      {
         if(host.State == CommunicationState.Opened)
         {
            throw new InvalidOperationException("Host is already opened");
         }

         Debug.Assert(SynchronizationContext.Current == null);//Can call only once

         AffinitySynchronizer affinitySynchronizer = new AffinitySynchronizer(threadName);
         SynchronizationContext.SetSynchronizationContext(affinitySynchronizer);

         host.Closing += delegate
                         {
                            using(affinitySynchronizer)
                            {}
                         };
      }
Ejemplo n.º 4
0
        /// <summary>
        /// Can only call before openning the host
        /// </summary>
        public static void SetThreadAffinity(this ServiceHost host, string threadName)
        {
            if (host.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Host is already opened");
            }

            Debug.Assert(SynchronizationContext.Current == null);//Can call only once

            AffinitySynchronizer affinitySynchronizer = new AffinitySynchronizer(threadName);

            SynchronizationContext.SetSynchronizationContext(affinitySynchronizer);

            host.Closing += delegate
            {
                using (affinitySynchronizer)
                {}
            };
        }