监控远程进程
我有一种停止服务的方法,但我还需要删除日志。通常这不是问题,但该过程在关闭之前可能需要一些时间。同样,虽然服务看起来已停止,但该过程确实需要额外的时间才能正确关闭。由于该进程仍在运行,我无法删除日志,因此我需要找到一种方法来监视 .exe 以了解何时可以安全地删除日志。
到目前为止,我最好的选择是 do while 循环,不幸的是,删除语句的第一次迭代抛出异常并停止程序。
do
{
// delete logs
}
while (System.Diagnostics.Process.GetProcessesByName(processName, machineName).Length > 0);
我确信有一个简单的解决方案,但我缺乏经验才是真正的问题。
I have a method that stops a service(s) but I also need to delete the logs. Usually this is not a problem but the process can take a little bit of time before closing. Again, although the service appears stopped, the process does take additional time to close properly. Since the process is still running, I cannot delete the logs so I need to find a way to monitor the .exe to know when its safe to delete the logs.
so far my best option is a do while loop, unfortunately the first iteration of the delete statement throws an exception and stops the program.
do
{
// delete logs
}
while (System.Diagnostics.Process.GetProcessesByName(processName, machineName).Length > 0);
Im sure there is a simple solution but my lack of experience is the real problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能也不是最好的答案,但您可以将循环反转为:
我想这会在执行内容之前评估循环的条件。但根据你的说法,在进程退出之前不会执行代码。
解决这个问题的一种黑客方法是执行循环,并在满足以下条件后手动中断:
This is probably not the best answer either, but you could invert the loop to:
I would suppose this would evalutate the condition of the loop before executing the contents. But according to your statements, this will not execute the code until the process has exited.
A hackish way around this is to perform a loop, and break out manually once the conditions: