基本信息
源码名称:c#自动启动进程并自动加载关闭winform前的值-定时器操作
源码大小:0.05M
文件格式:.zip
开发语言:C#
更新时间:2012-12-20
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
c#自动启动进程并自动加载关闭winform前的值-定时器操作
两个要点:一个是程序入口函数,一个是程序关闭前的处理以及System.Threading.Timer的简单用法
public int curIndex = 1; public Form1(string[] args) { InitializeComponent(); if(args.Length>1)this.textBox1.Text=args[0]; System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(AutoStart), curIndex, 1000, 1000); timer.Change(1000, 1000); } public void AutoStart(object test) { System.Diagnostics.Process curPro = System.Diagnostics.Process.GetCurrentProcess(); if (Convert.ToInt32(curIndex) >= 10) { //多个值(参数)之间用" " 隔开,这里的值 对应Program.cs中 Main函数的参数 string version = "v1.1"; string arguments = this.textBox1.Text " " DateTime.Now.ToString("yyyy-MM-dd HH:mm ss") " " version; Process.Start(Application.ExecutablePath, arguments); Environment.Exit(0); } this.label1.Text = (10-curIndex).ToString() "秒后将自动重启。。。"; curIndex = 1; }
这里是入口:
/// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(String[] arg) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); Application.Run(new Form1(arg)); }