System.Net.GlobalLog.ThreadContract C# (CSharp) Method

ThreadContract() private method

private ThreadContract ( ThreadKinds kind, ThreadKinds allowedSources, string errorMsg ) : void
kind ThreadKinds
allowedSources ThreadKinds
errorMsg string
return void
        internal static void ThreadContract(ThreadKinds kind, ThreadKinds allowedSources, string errorMsg)
        {
            if ((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown || (allowedSources & ThreadKinds.SourceMask) != allowedSources)
            {
                throw new InternalException();
            }

            ThreadKinds threadKind = CurrentThreadKind;
            Assert((threadKind & allowedSources) != 0, errorMsg, "Thread Contract Violation.|Expected source:({0}) Actual source:({1})", allowedSources , threadKind & ThreadKinds.SourceMask);
            Assert((threadKind & kind) == kind, errorMsg, "Thread Contract Violation.|Expected kind:({0}) Actual kind:({1})", kind, threadKind & ~ThreadKinds.SourceMask);
        }

Same methods

GlobalLog::ThreadContract ( ThreadKinds kind, string errorMsg ) : void

Usage Example

Beispiel #1
0
        /// <devdoc>
        ///    <para>
        ///       Forces all connections on the ConnectionGroup to not be KeepAlive.
        ///    </para>
        /// </devdoc>
        internal void DisableKeepAliveOnConnections()
        {
            // The timer thread is allowed to call this.  (It doesn't call user code and doesn't block.)
            GlobalLog.ThreadContract(ThreadKinds.Unknown, ThreadKinds.SafeSources | ThreadKinds.Timer, "ConnectionGroup#" + ValidationHelper.HashString(this) + "::DisableKeepAliveOnConnections");

            ArrayList connectionsToClose = new ArrayList();

            lock (m_ConnectionList) {
                GlobalLog.Print("ConnectionGroup#" + ValidationHelper.HashString(this) + "::DisableKeepAliveOnConnections() Name = " + m_Name + ", Count:" + m_ConnectionList.Count);
                foreach (Connection currentConnection in m_ConnectionList)
                {
                    //
                    // For each Connection set KeepAlive to false
                    //
                    GlobalLog.Print("ConnectionGroup#" + ValidationHelper.HashString(this) + "::DisableKeepAliveOnConnections() setting KeepAlive to false Connection#" + ValidationHelper.HashString(currentConnection));
                    connectionsToClose.Add(currentConnection);
                }
                m_ConnectionList.Clear();
            }

            foreach (Connection currentConnection in connectionsToClose)
            {
                currentConnection.CloseOnIdle();
            }
        }