zoukankan      html  css  js  c++  java
  • 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");
                }

  • 相关阅读:
    C# WinForm程序退出的方法
    SpringCloud 微服务框架
    idea 常用操作
    Maven 学习笔记
    SpringBoot 快速开发框架
    html 零散问题
    Java方法注释模板
    Seating Arrangement
    hibernate 离线查询(DetachedCriteria)
    hibernate qbc查询
  • 原文地址:https://www.cnblogs.com/wucg/p/1754589.html
Copyright © 2011-2022 走看看