我正在用C#创建一个用于监控某些应用程序的应用程序,所以如何知道exe运行的时间(例如:记事本)。
我尝试每1秒使用timer
运行检查if (Process.GetProcessesByName("process_name").Length > 0)
,但可能不是好方法。
答案 0 :(得分:0)
我认为最好的方法是设置计时器,它将检查每个运行进程,比方说,5秒。在计时器// This will return an empty array if notepad isn't running.
Process[] localByName = Process.GetProcessesByName("notepad");
事件中,按名称
items:[{
xtype: "combobox",
name: "TubeWellId",
fieldLabel: "Tubewell",
store: tube_well_store,
allowBlank: false,
displayField: "TubeWellName",
valueField: "TubeWellId",
queryMode: "local",
forceSelection: true,
listeners: {
select: function (combo) {
var getForm = this.up("form").getForm();
if (combo.getValue() === 1) {
getForm.findField("TubeWellDistance").setReadOnly(true);
} else {
getForm.findField("TubeWellDistance").setReadOnly(false);
}
}
}
}, {
xtype: "combobox",
name: "TubeWellDistance",
fieldLabel: "Tubewell Distance",
store: tube_well_store,
allowBlank: false,
displayField: "DistanceName",
valueField: "DistanceId",
queryMode: "local",
forceSelection: true,
}]
答案 1 :(得分:0)
我为你建造一个同样的应用程序。这是我的解决方案:
public void findProcess(string processName)
{
BackgroundWorker bg = new BackgroundWorker();
bg.DoWork += (object sender, DoWorkEventArgs e){
while(true)
{
Process[] process = Process.GetProcesses();
foreach(var p in process )
if(p.ProcessName.Equals(processName))
{
// TODO:
}
Thread.Sleep(1000);
}
};
}