我有一个C# WPF应用程序,在main()方法中,我检查某个条件是否成立,如果是,则运行不同的进程,但是我需要在一定的超时时间后启动该进程。例如:
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秒后启动新的进程。
谢谢!
这个可行吗?