今天幫同事寫了一個小東西,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();