创建进程时是否有系统事件?
创建新进程时是否有任何事件。 我正在编写用于检查某些进程的 ac# 应用程序,但我不想编写无限循环来连续迭代所有已知进程。 相反,我宁愿检查创建的每个进程或迭代由事件触发的所有当前进程。 有什么建议么?
Process[] pArray;
while (true)
{
pArray = Process.GetProcesses();
foreach (Process p in pArray)
{
foreach (String pName in listOfProcesses) //just a list of process names to search for
{
if (pName.Equals(p.ProcessName, StringComparison.CurrentCultureIgnoreCase))
{
//do some stuff
}
}
}
Thread.Sleep(refreshRate * 1000);
}
Is there any event when a new process is created. I'm writing a c# application that checks for certain processes, but I don't want to write an infinite loop to iterate through all known processes continuously. Instead, I rather check each process that is created or iterate through all current processes triggered by an event. Any suggestions?
Process[] pArray;
while (true)
{
pArray = Process.GetProcesses();
foreach (Process p in pArray)
{
foreach (String pName in listOfProcesses) //just a list of process names to search for
{
if (pName.Equals(p.ProcessName, StringComparison.CurrentCultureIgnoreCase))
{
//do some stuff
}
}
}
Thread.Sleep(refreshRate * 1000);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WMI 为您提供了一种监听进程创建(以及大约一百万个其他事物)的方法。 请参阅我的回答。
WMI gives you a means to listen for process creation (and about a million other things). See my answer here.