using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace 定时器
{
public partial class Form1 : Form
{
int zhouqi,myprocessId;
string lujing;
Process myprocess;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
lujing = textBox1.Text.Trim();
zhouqi = int.Parse(textBox2.Text);
myprocess = Process.Start(lujing);
myprocessId = myprocess.Id;
timer1.Interval = zhouqi;
timer1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
try
{
myprocess = Process.GetProcessById(myprocessId);
myprocess.Kill();
}
catch
{
}
this.Close();
}
private void timer1_Tick(object sender, EventArgs e)
{
myprocess = Process.GetProcessById(myprocessId);
myprocess.Kill();
Thread.Sleep(15000);
myprocess = Process.Start(lujing);
myprocessId = myprocess.Id;
}
}
}