StackTrace 进程

代码
public BaseForm()
{
InitializeComponent();
StackTrace st
= new StackTrace(true);
//this.Text = st.FrameCount.ToString();
Label lbl = new Label();
//lbl.Text = st.FrameCount.ToString();
//lbl.Text = st.GetFrame(1).GetFileName();

//这两种方法都可以取到类信息
string s1= st.GetFrame(1).GetMethod().DeclaringType.Name;

string s2 = st.GetFrame(1).GetMethod().ReflectedType.FullName;
lbl.Text
=s1+" || "+s2;

lbl.AutoSize
= true;
this.Controls.Add(lbl);

}

 

using System.Diagnostics;

我们在学习函数调用时,都知道每个函数都拥有自己的栈空间。一个函数被调用时,就创建一个新的栈空间。那么通过函数的嵌套调用最后就形成了一个函数调用堆栈。在c#中,使用StackTrace记录这个堆栈。你可以在程序运行过程中使用StackTrace得到当前堆栈的信息。

 

 

   try
            {
                Process.Start("regsvr.bat");
            }
            catch
            {
                Process MyProcess = new Process();
                MyProcess.StartInfo.FileName = "cmd.exe";
                MyProcess.StartInfo.UseShellExecute = false;
                MyProcess.StartInfo.RedirectStandardInput = true;
                MyProcess.StartInfo.RedirectStandardOutput = true;
                MyProcess.StartInfo.RedirectStandardError = true;
                MyProcess.StartInfo.CreateNoWindow = true;
                MyProcess.Start();
                string strStartPath = Application.StartupPath;
                MyProcess.StandardInput.WriteLine(strStartPath.Substring(0, 2));
                MyProcess.StandardInput.WriteLine("CD " + strStartPath.Substring(2));
                MyProcess.StandardInput.WriteLine("regsvr.bat");//直接结束进程ID
                MyProcess.StandardInput.WriteLine("Exit");
            }

 

posted @ 2010-06-09 11:03  庚武  Views(280)  Comments(0Edit  收藏  举报