今天帮同事写了一个小东西,web上有个功能是开始考试,然后到时结束改变状态
就给他说了Process调用进程,传参,定义一个timer,然后到时执行SQL改掉数据。
web
Process pro = new Process();
//控制台应用程序所在目录
pro.StartInfo.FileName = @"E:\测试目录\web调用exe\web调用exe\exe\bin\Debug\exe.exe";
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.CreateNoWindow = false;
pro.StartInfo.RedirectStandardOutput = true;
string Arguments = "123 5400";//控制台需要参数 "ID 考试秒数" 命令行参数,以空格隔开
pro.StartInfo.Arguments = Arguments;
pro.Start();
控制台
static System.Timers.Timer timer = null;
static void Main(string[] args)
{
string ID = args[0];
double S = Convert.ToDouble(args[1]);
timer = new System.Timers.Timer(S);
timer.AutoReset = false;
timer.Elapsed += (sender, e) => {
//执行考试结束的SQL
};
timer.Start();
我就这么发给他了,然后他拿去永远执行不了。。后来问我咋回事,我才想起之前写是服务,一直跑起的,控制台是执行完就结束释放了,根本不会等这个timer,后来就加上了等待,时间定义比timer多点点。
Thread.Sleep(Convert.ToInt32(S1.ToString())*1);
timer.Stop();