Beispiel #1
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 mainThreadId = Thread.CurrentThread.ManagedThreadId;

            using (DataTarget target = DataTarget.AttachToProcess(Process.GetCurrentProcess().Id, 5000, AttachFlag.Passive))
            {
                ClrRuntime runtime = target.ClrVersions.First().CreateRuntime();
                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 = ExceptionStack.Convert(thread.StackTrace);
                    ThreadInformations.Add(threadName, new ThreadInformation(threadName, false, frames));
                }
            }
        }
 /// <summary>
 /// Get a SourceData instance from Exception stack
 /// </summary>
 /// <param name="exceptionStack">Exception Stack</param>
 /// <returns>New instance of SoruceCode</returns>
 public static SourceCode FromExceptionStack(ExceptionStack exceptionStack)
 {
     return(new SourceCode()
     {
         StartColumn = exceptionStack.Column,
         StartLine = exceptionStack.Line,
         SourceCodeFullPath = exceptionStack.SourceCodeFullPath
     });
 }
Beispiel #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;
        }