I have a snippet of code which basically invokes an application using Process.Start()
method.
我有一段代码,它基本上使用Process.Start()方法调用应用程序。
ProcessStartInfo psi = new ProcessStartInfo(strAppPath);
psi.WindowStyle = ProcessWindowStyle.Maximized | ProcessWindowStyle.Normal;
//Starts the xyz application process.
Process xyzProcess = Process.Start(psi);
xyzProcess.WaitForInputIdle();
Although the process is started within few seconds, the application can take some amount of time to initialize completely. i.e my application xyz
can take 5 - 10 seconds depending on the machine it is running on (i.e less than 5 secs on a faster pc and >10 secs on slower pc's)
尽管该过程在几秒钟内启动,但应用程序可能需要一些时间才能完全初始化。即我的应用程序xyz可能需要5-10秒,具体取决于它运行的机器(即在较快的PC上小于5秒,在较慢的PC上小于10秒)
My question : Is there a way to track this ? By polling some property apart from waiting for sometime using Thread.Sleep(ms)
.
我的问题:有没有办法跟踪这个?通过使用Thread.Sleep(ms)轮询某些属性而不是等待某个时间。
I tried using the following approches in vain
我尝试使用以下approches是徒劳的
-
Polling
xyzProcess.Responding
property with a smallthread.sleep
使用小thread.sleep轮询xyzProcess.Responding属性
-
Dirty approach of polling
xyzProcess.MainWindowTitle
till it returns some non-null value.轮询xyzProcess.MainWindowTitle的脏方法,直到它返回一些非null值。
xyzProcess.WaitForInputIdle(sleeptime)
;
Please help
Thanks
1 个解决方案
#1
0
Are you just waiting for the application initialize, or are you just waiting for the application to do something?
您是在等待应用程序初始化,还是只是等待应用程序执行某些操作?
If it's just that the application needs to "do something" then can you not just wait for exit?
如果只是应用程序需要“做某事”那么你能不能等待退出?
xyzProcess.WaitForExit();
#1
0
Are you just waiting for the application initialize, or are you just waiting for the application to do something?
您是在等待应用程序初始化,还是只是等待应用程序执行某些操作?
If it's just that the application needs to "do something" then can you not just wait for exit?
如果只是应用程序需要“做某事”那么你能不能等待退出?
xyzProcess.WaitForExit();