GetCurrentThreadId() private method

private GetCurrentThreadId ( ) : uint
return uint
コード例 #1
0
ファイル: Logging.cs プロジェクト: dox0/DotNet471RS3
        internal static uint GetThreadId()
        {
            uint threadId = UnsafeNclNativeMethods.GetCurrentThreadId();

            if (threadId == 0)
            {
                threadId = (uint)Thread.CurrentThread.GetHashCode();
            }
            return(threadId);
        }
コード例 #2
0
ファイル: Logging.cs プロジェクト: samcf111/unityMono5.5.0
        internal static uint GetThreadId()
        {
#if MONO
            uint threadId = (uint)Thread.CurrentThread.ManagedThreadId;
#else
            uint threadId = UnsafeNclNativeMethods.GetCurrentThreadId();
#endif
            if (threadId == 0)
            {
                threadId = (uint)Thread.CurrentThread.GetHashCode();
            }
            return(threadId);
        }
コード例 #3
0
ファイル: _LoggingObject.cs プロジェクト: dox0/DotNet471RS3
        internal override void PrintLine(string msg)
        {
            if (_Finalized)
            {
                return;
            }
            string spc = "";

            _IamAlive++;

            spc = GetNestingString();

            string tickString = "";

            if (GlobalLog.s_UsePerfCounter)
            {
                long nowTicks;
                SafeNativeMethods.QueryPerformanceCounter(out nowTicks);
                if (_StartTicks > nowTicks) // counter reset, restart from 0
                {
                    _StartTicks = nowTicks;
                }
                nowTicks -= _StartTicks;
                if (GlobalLog.s_UseTimeSpan)
                {
                    tickString = new TimeSpan((long)(nowTicks * _NanosecondsPerTick)).ToString();
                    // note: TimeSpan().ToString() doesn't return the uSec part
                    // if its 0. .ToString() returns [H*]HH:MM:SS:uuuuuuu, hence 16
                    if (tickString.Length < 16)
                    {
                        tickString += ".0000000";
                    }
                }
                else
                {
                    tickString = ((double)nowTicks * _NanosecondsPerTick / 10000).ToString("f3");
                }
            }
            else
            {
                int nowMilliseconds = Environment.TickCount;
                if (_StartMilliseconds > nowMilliseconds)
                {
                    _StartMilliseconds = nowMilliseconds;
                }
                nowMilliseconds -= _StartMilliseconds;
                if (GlobalLog.s_UseTimeSpan)
                {
                    tickString = new TimeSpan(nowMilliseconds * 10000).ToString();
                    // note: TimeSpan().ToString() doesn't return the uSec part
                    // if its 0. .ToString() returns [H*]HH:MM:SS:uuuuuuu, hence 16
                    if (tickString.Length < 16)
                    {
                        tickString += ".0000000";
                    }
                }
                else
                {
                    tickString = nowMilliseconds.ToString();
                }
            }

            uint threadId = 0;

            if (GlobalLog.s_UseThreadId)
            {
                try {
                    object threadData = Thread.GetData(GlobalLog.s_ThreadIdSlot);
                    if (threadData != null)
                    {
                        threadId = (uint)threadData;
                    }
                }
                catch (Exception exception) {
                    if (exception is ThreadAbortException || exception is StackOverflowException || exception is OutOfMemoryException)
                    {
                        throw;
                    }
                }
                if (threadId == 0)
                {
                    threadId = UnsafeNclNativeMethods.GetCurrentThreadId();
                    Thread.SetData(GlobalLog.s_ThreadIdSlot, threadId);
                }
            }
            if (threadId == 0)
            {
                threadId = (uint)Thread.CurrentThread.GetHashCode();
            }

            string str = "[" + threadId.ToString("x8") + "]" + " (" + tickString + ") " + spc + msg;

            lock (this) {
                _AddCount++;
                _Logarray.Add(str);
                int MaxLines = GlobalLog.s_DumpToConsole ? 0 : GlobalLog.MaxLinesBeforeSave;
                if (_AddCount > MaxLines)
                {
                    _AddCount = 0;
                    DumpArray(false);
                    _Logarray = new ArrayList();
                }
            }
        }
コード例 #4
0
        internal override void PrintLine(string msg)
        {
            if (m_Finalized)
            {
                return;
            }
            string spc = "";

            _IamAlive++;

            spc = GetNestingString();

            string tickString = "";

            if (GlobalLog.s_UsePerfCounter)
            {
                long counter;
                SafeNativeMethods.QueryPerformanceCounter(out counter);
                if (_StartTickCountMicroseconds > counter) // counter reset, restart from 0
                {
                    _StartTickCountMicroseconds = counter;
                }
                counter -= _StartTickCountMicroseconds;
                if (GlobalLog.s_UseTimeSpan)
                {
                    tickString = new TimeSpan(counter / 100).ToString();
                    // note: TimeSpan().ToString() doesn't return the uSec part
                    // if its 0. .ToString() returns [H*]HH:MM:SS:uuuuuuu, hence 16
                    if (tickString.Length < 16)
                    {
                        tickString += ".0000000";
                    }
                }
                else
                {
                    tickString = ((double)counter * _MillisecondsPerTicks).ToString("f3");
                }
            }
            else
            {
                int counter = Environment.TickCount;
                if (_StartTickCountMilliseconds > counter)
                {
                    _StartTickCountMilliseconds = counter;
                }
                counter -= _StartTickCountMilliseconds;
                if (GlobalLog.s_UseTimeSpan)
                {
                    tickString = new TimeSpan(counter * 10000).ToString();
                    // note: TimeSpan().ToString() doesn't return the uSec part
                    // if its 0. .ToString() returns [H*]HH:MM:SS:uuuuuuu, hence 16
                    if (tickString.Length < 16)
                    {
                        tickString += ".0000000";
                    }
                }
                else
                {
                    tickString = (counter).ToString();
                }
            }

            int threadId = 0;

            if (GlobalLog.s_UseThreadId)
            {
                try {
                    threadId = (int)Thread.GetData(GlobalLog.s_ThreadIdSlot);
                }
                catch {
                }
                if (threadId == 0)
                {
                    threadId = UnsafeNclNativeMethods.GetCurrentThreadId();
                    Thread.SetData(GlobalLog.s_ThreadIdSlot, threadId);
                }
            }
            if (threadId == 0)
            {
                threadId = Thread.CurrentThread.GetHashCode();
            }

            string str = String.Format("[{0:x8}]", threadId) + " (" + tickString + ") " + spc + msg;

            Monitor.Enter(this);

            _AddCount++;
            _Logarray.Add(str);

            int MaxLines = GlobalLog.s_DumpToConsole ? 0 : GlobalLog.MaxLinesBeforeSave;

            if (_AddCount > MaxLines)
            {
                _AddCount = 0;

                if (!GlobalLog.SaveOnlyOnError || GlobalLog.s_DumpToConsole)
                {
                    DumpArray(false);
                }

                _Logarray = new ArrayList();
            }

            Monitor.Exit(this);
        }