【发布时间】:2012-02-28 00:01:01
【问题描述】:
我正在制作一个任务管理器应用程序(服务器客户端)..所以我从服务器获取处理器列表作为字符串。
正如您在任务管理器快照中看到的那样,我的问题是 60-65% 的处理器计数未能进入服务器端。请注意,服务器应用程序已调试为 管理员
服务器代码:
public void GetProcessors()
{
int i =0,j = 0;
string answer = "";
foreach (Process p in Process.GetProcesses())
{
try
{
answer += p.MainModule.ModuleName
+ "|" + p.Id.ToString()
+ "|" + string.Format("{0:N0} K", p.WorkingSet64 / 1024)
+ "|" + p.MainModule.FileVersionInfo.FileDescription;
i++;
answer += "?";
}
catch
{
j++;
}
}
answer = answer.Remove(answer.Length - 1, 1);
send(string.Format("get<{0}<{1}<{2}", answer, i, j));
}
客户端: 这从任务管理器类中调用了 getProcessors 方法
switch(command[1])
{
case "get":
Console.WriteLine(command[2]);
if (InvokeRequired)
{
Action a = () => taskManager1.GetProcessors(command[2], command[3], command[4]);
Invoke(a);
}
break;
default:
break;
}
(客户端)任务管理器类:
public void GetProcessors(string cmd,string success,string fail)
{
string[] Processors = cmd.Split('?');
foreach (string process in Processors)
{
string[] info = process.Split('|');
if (info.Length < 4)
{
MessageBox.Show(info.Length.ToString());
continue;
}
ListViewItem item = new ListViewItem(info[0]);
item.SubItems.Add(info[1]);
item.SubItems.Add(info[2]);
item.SubItems.Add(info[3]);
listView1.Items.Add(item);
}
labelProcess.Text = string.Format("Processors: {0}", success);
failedLabel.Text = string.Format("Failed: {0}", fail);
}
我得到了那些例外
85 FAILS : 83 是 {"A 32 bit processes cannot access modules of a 64 bit process."}
其他 2 个失败:{“无法枚举进程模块。”}
在我编辑了代码并尝试在不使用 Process.MainModule 的情况下运行它之后......它给了我:
process : 147 .. FAIL : 0 .. 那为什么我无法访问 process.MainModule ?
我该如何解决这个问题??
【问题讨论】:
-
您可以尝试将
(Exception ex)添加到catch 块中:catch {j++;}吗?有什么例外? -
处理器和进程是非常不同的东西。前者是一块硬件。后者是正在执行的程序。
-
我有 86 个(共 88 个)失败此异常消息:{“32 位进程无法访问 64 位进程的模块。”} 和 2 个(共 88 个)失败此异常消息:{“无法枚举流程模块。"}
-
是的,我明白了.. 但无论如何我可以得到我想要的信息吗?
-
当我将调试器模式更改为 x64 时,它获得了成功 146,失败 3 是一个很好的结果.. 但是现在我的程序是 64 位的.. 我需要我的应用程序在任何电脑上运行..我必须制作两份我的申请表吗?????
标签: c# process permissions client-server admin