Example #1
0
        /// <summary>
        /// Generate information for current thread
        /// </summary>
        /// <param name="exceptionStack">Current BacktraceReport exception stack</param>
        private void GenerateCurrentThreadInformation(IEnumerable <BacktraceStackFrame> exceptionStack)
        {
            var current = Thread.CurrentThread;
            //get current thread id
            string generatedMainThreadId = current.GenerateValidThreadName().ToLower();

            ThreadInformations[generatedMainThreadId] = new ThreadInformation(current, exceptionStack, true);
            //set currentThreadId
            MainThread = generatedMainThreadId;
        }
Example #2
0
        /// <summary>
        /// Get all used threads in calling assembly. Function ignore current thread Id
        /// </summary>
        /// <param name="callingAssembly">Calling assembly</param>
        private void GetUsedThreads(Assembly callingAssembly)
        {
            var currentPlatform = Environment.OSVersion.Platform.ToString();

            if (!currentPlatform.ToLower().StartsWith("win"))
            {
                //avoid getting system threads for .NET Framework 4.5 in Untiy Environment
                return;
            }
            var mainThreadId = Thread.CurrentThread.ManagedThreadId;

            using (DataTarget target = DataTarget.AttachToProcess(Process.GetCurrentProcess().Id, 5000, AttachFlag.Passive))
            {
                if (target.ClrVersions == null || !target.ClrVersions.Any())
                {
                    return;
                }
                ClrRuntime runtime = null;
                try
                {
                    runtime = target.ClrVersions.First().CreateRuntime();
                }
                catch (ClrDiagnosticsException)
                {
                    //we cannot create runtime for current applications state
                    return;
                }
                foreach (ClrThread thread in runtime.Threads)
                {
                    if (thread.ManagedThreadId == mainThreadId)
                    {
                        //main thread catched
                        continue;
                    }
                    //ClrThread doesn't have any information about thread
                    string threadName = thread.OSThreadId.ToString();
                    if (string.IsNullOrEmpty(threadName))
                    {
                        threadName = thread.ManagedThreadId.ToString();
                    }
                    var frames = new List <BacktraceStackFrame>();
                    foreach (var frame in thread.StackTrace)
                    {
                        if (frame.Method == null)
                        {
                            continue;
                        }
                        frames.Add(new BacktraceStackFrame(frame));
                    }
                    ThreadInformations[threadName] = new ThreadInformation(threadName, false, frames);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Generate information for current thread
        /// </summary>
        private void GenerateCurrentThreadInformation(Assembly callingAssembly, IEnumerable <ExceptionStack> exceptionStack)
        {
            var current = Thread.CurrentThread;
            //get a current thread stack trace
            //in thread stack trace we concatenate current thread stack trace and stack trace available in exception object
            var currentThreadStackTrace = ExceptionStack.FromCurrentThread(callingAssembly.GetName().Name, exceptionStack);

            //get current thread id
            string generatedMainThreadId = ThreadInformation.GenerateValidThreadName(current);

            ThreadInformations[generatedMainThreadId] = new ThreadInformation(current, currentThreadStackTrace);
            //set currentThreadId
            MainThread = generatedMainThreadId;
        }