How to get the current stack trace information in C#

1 Answer

0 votes
using System.Diagnostics;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = Environment.StackTrace;
        }
    }
}




/*
 * run:
 
   at System.Environment.get_StackTrace()
   at WinFormsApp1.Form1.button1_Click(Object sender, EventArgs e) in C:\source\repos\WinFormsApp1\WinFormsApp1\Form1.cs:line 14
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)
   at Interop.User32.DispatchMessageW(MSG& msg)
   at Interop.User32.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
   at WinFormsApp1.Program.Main() in C:\source\repos\WinFormsApp1\WinFormsApp1\Program.cs:line 14
  
 */

 



answered Nov 18, 2023 by avibootz

Related questions

3 answers 214 views
1 answer 198 views
1 answer 142 views
1 answer 160 views
1 answer 160 views
...