[問題] 重複IF的情況

作者: houit123 (houit123)   2016-11-23 02:26:32
現在會自動在duration時間完結後關掉USB.EXE 但duration時間後 IF還會一直執行
USB.EXE 然後ELSE會一直把USB.EXE殺掉 USB.EXE一直打開重關掉
是那裡出現了問題
bool usbStarted = false;
if (span.Seconds > 0 && span.Seconds < duration)
{
if (!usbStarted)
{
Process.Start(@"C:\Users\USER\Desktop\usb.exe");
usbStarted = true;
}
else
{
timer2.Interval = duration * 60;
timer1.Start();
foreach (Process prc in Process.GetProcessesByName("usb"))
{
prc.Kill();
}
usbStarted = false;
}
}
作者: petercoin (彼得幣)   2016-11-23 09:56:00
看起來是span.Seconds沒有大於duration所以會一直進迴圈?
作者: gundan (彈彈的哀傷)   2016-11-23 16:01:00
你debug一行一行跑,看變數內容就會知道啦
作者: mepowerlmay (用心,找對人)   2016-11-24 20:08:00
你debug一行一行跑,看變數內容就會知道啦
作者: Peruheru (還在想)   2016-11-25 10:36:00
你 看 就 知道啦
作者: Qtter (Qtter)   2016-11-25 14:29:00
你debug一 跑,看變數 就 知 啦

Links booklink

Contact Us: admin [ a t ] ucptt.com