Пример #1
0
        /// <summary>
        /// Gets the <see cref="ProfilerDataCollection" /> for the specified thread.
        /// </summary>
        /// <param name="threadId">
        /// The thread ID, a unique identifier for the managed thread. (See
        /// <see cref="Thread.ManagedThreadId"/>.)
        /// </param>
        /// <returns>
        /// The <see cref="ProfilerDataCollection" /> for the specified thread.
        /// </returns>
        /// <remarks>
        /// <strong>Thread-Safety:</strong> Accessing the profiler data of a thread that is not the
        /// current thread is not thread-safe.
        /// </remarks>
        public static ProfilerDataCollection Get(int threadId)
        {
            ProfilerDataCollection collection;

            if (!_data.TryGet(threadId, out collection))
            {
                // ProfilerDataCollection does not exist. --> Create a new one.
                collection = new ProfilerDataCollection("Unnamed", threadId);
                _data.Add(threadId, collection);
            }

            return(collection);
        }
Пример #2
0
        /// <summary>
        /// Gets the <see cref="ProfilerDataCollection"/> for the specified thread.
        /// (Not available on these platforms: WinRT)
        /// </summary>
        /// <param name="thread">The thread.</param>
        /// <returns>The <see cref="ProfilerDataCollection"/> for the specified thread.</returns>
        /// <remarks>
        /// <para>
        /// <strong>Thread-Safety:</strong> Accessing the profiler data of a thread that is not the
        /// current thread is not thread-safe.
        /// </para>
        /// <para>
        /// This method is not available on the following platforms: WinRT
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="thread"/> is <see langword="null"/>.
        /// </exception>
        public static ProfilerDataCollection Get(Thread thread)
        {
            if (thread == null)
            {
                throw new ArgumentNullException("thread");
            }

            ProfilerDataCollection collection;
            int threadId = thread.ManagedThreadId;

            if (!_data.TryGet(threadId, out collection))
            {
                // ProfilerDataCollection does not exist. --> Create a new one.
                collection = new ProfilerDataCollection(thread.Name, threadId);
                _data.Add(threadId, collection);
            }

            return(collection);
        }