我有一个c#wpf应用程序,在main()方法中,我检查某个条件,如果它是真的,我运行一个不同的进程,但是,我需要在某个超时后启动进程。因此,例如:在C#中的特定时间间隔后启动一个进程?
override OnStartUp()
{
if(condition == true)
{
ProcessStartInfo p = new ProcessStartInfo("filePath");
p.Start(); // This should wait for like say 5 seconds and then start.
return; // This will exit the current program.
}
}
我可以使用Thread.Sleep(),但也会导致当前的程序睡眠。换句话说,我希望当前的程序立即终止,然后在5秒后启动新的进程。
谢谢!
这可能吗?
使用'Timer'到X一段时间后 – Servy
执行一些动作@Servy:在当前进程已经终止后,这不会导致行动。 –
是的..当前进程必须终止,并且只有在新进程需要等待5秒才能启动之后...谢谢 – user1202434