我的winform程序,怎么能实现在窗口上点击一个按钮,该程序能退出并再次启动?谢谢!

解决方案 »

  1.   

    WinForm应用程序重启自己。 
    可以使用Timer来完成这个操作.  
    在.Net中提供了两个Timer.  
    如果应用程序是WinForm,  可以使用System.Windows.Forms.Timer.  
    如果不是WinForm程序,  我们可以使用System.Threading.Timer.然后,  在Timer触发的Event  handler中写如下代码来起一个新的进程运行您的这个应用程序.  
                          
    //这里可能要加一个检测语句,  判断只有一个或者两个进程运行的这个应用程序在系统中运行,
    /否则,  程序就会一直不断自杀起新进程,  不断重复ProcessStartInfo  pi  =  new  ProcessStartInfo(Assembly.GetExecutingAssembly().Location);
    Process  prc  =  new  Process();
    prc.StartInfo  =  pi;                        
    prc.Start();
    //杀掉自己这个进程
    Process.GetCurrentProcess().Kill();
      

  2.   

    呵呵 ^_^
    Application.Restart这个更方便...
      

  3.   

    Application.Restart
    我这里怎么没有这个方法啊,我用的是.net2003,有Application.Exit
      

  4.   

    Application.Restart 2005有
    2003 就用hertcloud(·£孙子兵法£·)的方法实验下,不知道杀死自己后是否还能重起?
    不行就做个外壳来控制!
      

  5.   

    在2003下只有做个外壳来实现了,或者试试用wmi来做
      

  6.   

    2003可以用System.Diagnostics.Process.Start("Path");
      

  7.   

    Application.Restart();在2003下没有。
    不想换2005的话就用hertcloud(·£孙子兵法£·) 的方法吧
      

  8.   

    既然程序只是个画面的话,那么只要关闭画面在开就是了。
    [STAThread]
    static void Main() 
    {
    new Form1().Show();
    System.Windows.Forms.Application.Run();
    } private void button1_Click(object sender, System.EventArgs e)
    {
    this.Close();
    new Form1().Show();
    }
      

  9.   

    我用了Application.Restart(); 但是会多出来了应用程序。成了两个应用程序运行。
    Application.Restart();
    Application.Exit(); 这样写也不行