IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

[C#] "Access is denied" pour récupérer le temps processeur


Sujet :

Windows Forms

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    73
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : France, Calvados (Basse Normandie)

    Informations forums :
    Inscription : Juin 2006
    Messages : 73
    Points : 58
    Points
    58
    Par défaut [C#] "Access is denied" pour récupérer le temps processeur
    Bonjour,

    J'essai de récupérer le temps processeur occupé par chacun des process tournant sur mon PC. J'arrive à récupérer le nom du process, son ID, la taille mémoire utilisée mais j'ai systématiquement une Win32Exception : access is denied quand je veux récupérer le temps processor.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
     processListView.Items.Clear();
                foreach (Process process in Process.GetProcesses()) {
                    ListViewItem currentItem = new ListViewItem(process.Id.ToString(), 0);
                    currentItem.SubItems.Add(process.ProcessName);
    currentItem.SubItems.Add(process.TotalProcessorTime.ToString());
                    currentItem.SubItems.Add(""+(process.WorkingSet64/1024)+" K");             
                    processListView.Items.Add(currentItem);
                }
    qqun aurait il une idée ?

    merci d'avance...

  2. #2
    Membre éclairé
    Avatar de shwin
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    568
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2003
    Messages : 568
    Points : 777
    Points
    777
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    foreach (Process process in Process.GetProcesses())
                {
                    if (process.Id != 0)
                    System.Diagnostics.Debug.WriteLine(process.TotalProcessorTime.ToString());
                }
    Il faut que tu évite d'aller chercher le process idle (processname = idle & processId = 0). C'est pour ca qu'il te lance une exception
    - process {System.Diagnostics.Process (Idle)} System.Diagnostics.Process
    + base {System.Diagnostics.Process (Idle)} System.ComponentModel.Component {System.Diagnostics.Process}
    BasePriority 0 int
    EnableRaisingEvents false bool
    + ExitCode 'process.ExitCode' threw an exception of type 'System.ComponentModel.Win32Exception' int {System.ComponentModel.Win32Exception}
    + ExitTime 'process.ExitTime' threw an exception of type 'System.ComponentModel.Win32Exception' System.DateTime {System.ComponentModel.Win32Exception}
    + Handle 'process.Handle' threw an exception of type 'System.ComponentModel.Win32Exception' System.IntPtr {System.ComponentModel.Win32Exception}
    HandleCount 0 int
    + HasExited 'process.HasExited' threw an exception of type 'System.ComponentModel.Win32Exception' bool {System.ComponentModel.Win32Exception}
    Id 0 int
    MachineName "." string
    + MainModule 'process.MainModule' threw an exception of type 'System.ComponentModel.Win32Exception' System.Diagnostics.ProcessModule {System.ComponentModel.Win32Exception}
    + MainWindowHandle 0 System.IntPtr
    MainWindowTitle "" string
    + MaxWorkingSet 'process.MaxWorkingSet' threw an exception of type 'System.ComponentModel.Win32Exception' System.IntPtr {System.ComponentModel.Win32Exception}
    + MinWorkingSet 'process.MinWorkingSet' threw an exception of type 'System.ComponentModel.Win32Exception' System.IntPtr {System.ComponentModel.Win32Exception}
    + Modules 'process.Modules' threw an exception of type 'System.ComponentModel.Win32Exception' System.Diagnostics.ProcessModuleCollection {System.ComponentModel.Win32Exception}
    NonpagedSystemMemorySize 0 int
    NonpagedSystemMemorySize64 0 long
    PagedMemorySize 0 int
    PagedMemorySize64 0 long
    PagedSystemMemorySize 0 int
    PagedSystemMemorySize64 0 long
    PeakPagedMemorySize 0 int
    PeakPagedMemorySize64 0 long
    PeakVirtualMemorySize 0 int
    PeakVirtualMemorySize64 0 long
    PeakWorkingSet 0 int
    PeakWorkingSet64 0 long
    + PriorityBoostEnabled 'process.PriorityBoostEnabled' threw an exception of type 'System.ComponentModel.Win32Exception' bool {System.ComponentModel.Win32Exception}
    + PriorityClass 'process.PriorityClass' threw an exception of type 'System.ComponentModel.Win32Exception' System.Diagnostics.ProcessPriorityClass {System.ComponentModel.Win32Exception}
    PrivateMemorySize 0 int
    PrivateMemorySize64 0 long
    + PrivilegedProcessorTime 'process.PrivilegedProcessorTime' threw an exception of type 'System.ComponentModel.Win32Exception' System.TimeSpan {System.ComponentModel.Win32Exception}
    ProcessName "Idle" string
    + ProcessorAffinity 'process.ProcessorAffinity' threw an exception of type 'System.ComponentModel.Win32Exception' System.IntPtr {System.ComponentModel.Win32Exception}
    Responding true bool
    SessionId 0 int
    + StandardError 'process.StandardError' threw an exception of type 'System.InvalidOperationException' System.IO.StreamReader {System.InvalidOperationException}
    + StandardInput 'process.StandardInput' threw an exception of type 'System.InvalidOperationException' System.IO.StreamWriter {System.InvalidOperationException}
    + StandardOutput 'process.StandardOutput' threw an exception of type 'System.InvalidOperationException' System.IO.StreamReader {System.InvalidOperationException}
    + StartInfo {System.Diagnostics.ProcessStartInfo} System.Diagnostics.ProcessStartInfo
    + StartTime 'process.StartTime' threw an exception of type 'System.ComponentModel.Win32Exception' System.DateTime {System.ComponentModel.Win32Exception}
    SynchronizingObject null System.ComponentModel.ISynchronizeInvoke
    + Threads {System.Diagnostics.ProcessThreadCollection} System.Diagnostics.ProcessThreadCollection
    + TotalProcessorTime 'process.TotalProcessorTime' threw an exception of type 'System.ComponentModel.Win32Exception' System.TimeSpan {System.ComponentModel.Win32Exception}
    + UserProcessorTime 'process.UserProcessorTime' threw an exception of type 'System.ComponentModel.Win32Exception' System.TimeSpan {System.ComponentModel.Win32Exception}
    VirtualMemorySize 0 int
    VirtualMemorySize64 0 long
    WorkingSet 16384 int
    WorkingSet64 16384 long
    + Static members
    + Non-Public members
    Ce qui nous intéresse est ceci:
    + TotalProcessorTime 'process.TotalProcessorTime' threw an exception of type 'System.ComponentModel.Win32Exception' System.TimeSpan {System.ComponentModel.Win32Exception}

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [ACCESS][JAVA][INSERT][QUOTE]Pb insertion quot
    Par 205 dans le forum Requêtes et SQL.
    Réponses: 3
    Dernier message: 31/01/2008, 17h00
  2. Réponses: 5
    Dernier message: 09/09/2005, 17h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo