本文介绍了单声道错误的解决方法:Wrong Process.ProcessName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您使用 mono 并使用 Process.ProcessName,您可能会在某些计算机上得到错误的结果.

If you work with mono and use Process.ProcessName you may get wrong results on some computers.

例如,您可能会得到kdeinit4"(在 SUSE 上可见),而不是进程名称kwrite".

For example instead of the process name "kwrite" you may get "kdeinit4" (seen on SUSE).

在 Ubuntu 上,我什至看到过像kdeinit4;5535948c (deleted)"而不是kwrite"这样的废话.

On Ubuntu I have even seen complete bullshit like "kdeinit4;5535948c (deleted)" instead of "kwrite".

注意:在其他计算机上,结果可能是正确的.

Note: On other computers the result may be correct.

如果我使用 Process.MainModule.ModuleName 它会返回相同的错误名称.如果我使用 Process.MainModule.FileName 它会给出错误的路径.除此之外,这些命令非常慢.

If I use Process.MainModule.ModuleName it retruns the same wrong name.And if I use Process.MainModule.FileName it gives the wrong path. Apart from that these commands are EXTREMELY slow.

所以无论我尝试什么,它都充满了错误.我能做什么?

So whatever I try it is full of bugs.What can I do?

推荐答案

解决方法可以用两行:

String sProcFile = String.Format("/proc/{0}/comm", proc.Id);
String sProcName = File.ReadAllText(sProcFile).Trim();

它在 ProcessName 失败的所有计算机上就像一个魅力.

It works like a charm on all computers where ProcessName fails.

这篇关于单声道错误的解决方法:Wrong Process.ProcessName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 02:31