检查天气是否正在运行 [英] Check weather a perticuler process is running or not
本文介绍了检查天气是否正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我正在尝试使用以下代码检查天气是否正常运行
Dim myProcesses() As 处理
myProcesses = Process.GetProcessesByName( devenv.exe)
如果 myProcesses.Count> 0 然后
lblClient.Text = 正在运行
否则
lblClient.Text = 未运行
结束 如果
但它没有显示输出。
请告诉我哪里错了..
谢谢
解决方案
< blockquote>当我使用没有.exe扩展名的进程名称时它工作
如果你获得了类型System.Diagnostics.Process类型进程的实例
,它确实至少在通话时运行。稍后,您可以这样检查: http://msdn.microsoft .com / zh-cn / library / system.diagnostics.process.hasexited.aspx [ ^ ]。
但是如果你只需要等待进程退出,你不应该等待它,这是一种非常低效的技术。您需要这样做:
http://msdn.microsoft.com/ en-us / library / fb4aw7b8.aspx [ ^ ],
http://msdn.microsoft。 com / en-us / library / ty0d8k56.aspx [ ^ ]。
如果你使用WaitForExit
调用线程不会浪费等待期间的任何CPU时间。它将被设置为一个特殊的等待状态:关闭并且不会被调度回执行,直到它被相关进程终止(或超时)唤醒。
-SA
Hi all
I am trying to check weather a perticular process is running or not using the below code
Dim myProcesses() As Process
myProcesses = Process.GetProcessesByName("devenv.exe")
If myProcesses.Count > 0 Then
lblClient.Text = "Running"
Else
lblClient.Text = "Not Running"
End If
But it's not showing the output.
Please tell me where i am wrong..
Thank you
解决方案
It worked when i am using the process name without the extension of .exe
If you obtained the instance of some process of the typeSystem.Diagnostics.Process
, it was certain running at least at the moment of call. Later on, you can check it up this way: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.hasexited.aspx[^].
But if you simply need to wait for process exit, you should not speen-wait for it, which is a very inefficient technique. You need to do this:
http://msdn.microsoft.com/en-us/library/fb4aw7b8.aspx[^],
http://msdn.microsoft.com/en-us/library/ty0d8k56.aspx[^].
If you useWaitForExit
the calling thread won't waste any CPU time during wait. It will be set to a special wait state: switched off and not scheduled back to execution until it is waken up by the termination of the process in question (or by a timeout).
—SA
这篇关于检查天气是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文