C# 如何 实现 当程序关闭后 再重新运行?从 任务管理器  直接关闭后 也能 自动 重新 运行 ..   怎么弄??...谢谢!~

解决方案 »

  1.   

    做成windowservices,然后设置为操作失败后重新启动模式
      

  2.   

    在写一个外挂程序
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;using System.Configuration;namespace auto_run
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            string name = ConfigurationSettings.AppSettings["File_Server_Name"];
            private void Form1_SizeChanged(object sender, EventArgs e)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    //e.Cancel = true; // 取消关闭窗体
                    //this.Hide();
                    //this.ShowInTaskbar = false;
                    //this.notifyIcon1.Visible = true;//显示托盘图标 
                }
            }        private void cToolStripMenuItem_Click(object sender, EventArgs e)
            {
                this.Close();
            }        private void 运行文件服务器ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                try
                {
                    System.Diagnostics.Process.Start(name);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    MessageBox.Show("文件传送服务器端不存在!");
                }
            }        private void timer1_Tick(object sender, EventArgs e)
            {            Process[] ravProcesses = Process.GetProcessesByName("" + name + "");
                if (ravProcesses.Length == 0)
                {
                    //程序没有运行
                    try
                    {
                        System.Diagnostics.Process.Start(name);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }        }        private void SaveSettings()
            {
                Microsoft.Win32.RegistryKey Reg;
                Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                Reg.SetValue("Auto_File_Server", Application.ExecutablePath);
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                //SaveSettings();
                this.Hide();
            }
        }
    }