Laden...

Prozesse auslesen > langsam :(

Erstellt von Thorsten1983 vor 17 Jahren Letzter Beitrag vor 17 Jahren 2.093 Views
T
Thorsten1983 Themenstarter:in
147 Beiträge seit 2005
vor 17 Jahren
Prozesse auslesen > langsam :(

Hallo,

ich lese beim start meiner Anwendung die Windows Prozessliste über

Process.GetProcesses();

aus. Lt. meiner Log Datei dauert dies auf einem Windows 2000 Server OS ca 40 Sekunden.

Da dies entscheident zu lange ist, habe ich die ermittlung des Prozesses umgestellt auf

Process.GetProcessesByName("MeinProc");

diese Art der Prozessabfrage dauert ca 36 Sekunden, was mir immer noch entschieden zu lange ist.

Hat jemand eine Idee wie ich das schneller machen kann?

THX schon mal

S
8.746 Beiträge seit 2005
vor 17 Jahren

Bei mir dauert das ungefähr 1 ms (2000 Prof.). Wie hast du denn gemessen?

T
Thorsten1983 Themenstarter:in
147 Beiträge seit 2005
vor 17 Jahren

Habe vor start der anweisung und danach eine Zeiel im StreamWriter dazugefügt. Das dürfte ja maximal das Ergebnis um 2-3 Sekunden verfälschen.

Ich verstehe halt nur nicht wie es da von System zu System solche Unterschiede geben kann.

Gibt es denn keine andere Möglichkeit rauszufinden ob ein Prozess aktiv ist.

S
8.746 Beiträge seit 2005
vor 17 Jahren

Zeig doch mal den Code....

Hier hab ich noch was gefunden:

Why does the Process class have a dependency on the performance counter?
The Process class exposes performance information about processes. In order to get performance information about remote processes, we need to query performance information on a remote machine. We used the same code to get performance information about processes on a local machine in Everett. That's why the Process class has a dependency on the performance counter. However, this approach has several problems:

  1. Performance information is not available to a non-admin account, which is not in the Performance Counter Users Group on Windows Server 2003. So the Process class could not get process performance information in this case.
  2. Getting performance data from all the processes on the machine is pretty expensive. The operating system (OS) might load lots of DLLs and it might take seconds to complete. The floppy drive light will be on when the OS tries to find the index for some performance counter.
  3. If the performance counter data was corrupted for any reason, the Process class could throw an exception while trying to convert some raw performance information into DateTime.
  4. The Process class could not be used to get process information on machines without the process performance counter. Performance counters can be disabled in Windows. See the following link for details: http://www.microsoft.com/windows2000/techinfo/reskit/en-us/default.asp?url=/windows2000/techinfo/ reskit/en-us/regentry/94214.asp

The good news is that we have changed the implementation of the Process class in Visual Studio 2005 (our next release, code-named Whidbey). The Process class doesn't have a dependency on performance counter information any more (this is only true for local processes).

T
Thorsten1983 Themenstarter:in
147 Beiträge seit 2005
vor 17 Jahren

Hmm, dachte mir dass die da im 2er Framework was gemacht haben, leider kann ich die Anwendung nicht auf .Net 2.0 migrieren.

Also, so frage ich ab ob mehr als die aktuelle Instanz der Applikation laufen


if(Process.GetProcessesByName(Application.ProductName).Length > 1){
	MessageBox.Show("ServerEye2 Administrator ist bereits gestartet.","ServerEye2: Hinweis",MessageBoxButtons.OK,MessageBoxIcon.Information);
	System.Environment.Exit(0);
}

das ist auf jeden Fall schon mal die schickere der beiden Lösungen. Mit

Process.GetProcesses() 

finde ich es "unschöner" 😁