Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - System.Environment.TickCount cosa restituisce?
Forum - C# / VB.NET - System.Environment.TickCount cosa restituisce? - Pagina 3

Pagine: [ 1 2 3 ] Precedente | Prossimo
Avatar
alip1 (Normal User)
Pro


Messaggi: 139
Iscritto: 12/08/2019

Segnala al moderatore
Postato alle 20:25
Venerdì, 06/03/2020
Grazie domattina vedrò meglio l'impostazione risparmio energia e riproverò. Poi farò sapere

PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1344
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 13:20
Sabato, 07/03/2020
Alla luce di quanto postato da alip1, programma aggiornato.
Codice sorgente - presumibilmente VB.NET

  1. Public Class Form1
  2.  
  3.     Dim RiTeBo As New RichTextBox ' per visualizzare i risultati
  4.     Dim Button1 As New Button
  5.     Dim Button2 As New Button
  6.     Dim Label1 As New Label
  7.     Dim Label2 As New Label
  8.     Dim Eventi As New List(Of String) ' matrice di accumulo
  9.     Dim Timer1 As Timer
  10.     Dim OraACCENSIONE As Date? ' il punto interrogativo rende la variabile nullable
  11.     Dim OraACCENSIONE2 As Date
  12.  
  13.     ' ***********************************************************
  14.     ' *                                                         *
  15.     ' *       LETTUTRA LOG SYSTEM DIAGNOSTIC DI WINDOWS         *
  16.     ' *                                                         *
  17.     ' *       IN QUESTO ESEMPIO RICERCA DI SOSPENSIONI          *
  18.     ' *                 E ARRESTI DI WINDOWS                    *
  19.     ' *                                                         *
  20.     ' *    CAMBIANDO l'ID, SI POSSONO CERCARE ALTRI EVENTI      *
  21.     ' *                                                         *
  22.     ' * TOGLIENDO L'IF SI POSSONO VISUALIZZARE TUTTI GLI EVENTI *
  23.     ' *                                                         *
  24.     ' ***********************************************************
  25.  
  26.     Private Sub Button1_Click(sender As Object, e As EventArgs)
  27.         Dim EventoLogApp As New System.Diagnostics.EventLog("System") ' applicazione di diagnostica
  28.         Eventi.Clear()
  29.         RiTeBo.Clear()
  30.         RiTeBo.Refresh()
  31.         ' ricerca dall'inizio, ID 12 = avvio, ID 13 = arresto (non si generano con sospensione o ibernazione)
  32.         For i = 1 To EventoLogApp.Entries.Count - 1
  33.             ' ogni 50 eventi aggiorno la label (evita rallentamento)
  34.             If i Mod 50 = 0 Then Label1.Text = i & "/" & EventoLogApp.Entries.Count : Label1.Refresh()
  35.             If EventoLogApp.Entries(i).InstanceId.ToString = 12 Then
  36.                 Eventi.Add("------ AVVIO SISTEMA IN EVENTO N. " & i)
  37.                 Eventi.Add(EventoLogApp.Entries(i).TimeGenerated.ToString)
  38.                 Eventi.Add(EventoLogApp.Entries(i).Source.ToString)
  39.                 Eventi.Add("ID: " & EventoLogApp.Entries(i).InstanceId.ToString)
  40.                 Eventi.Add("PC: " & EventoLogApp.Entries(i).MachineName.ToString)
  41.                 Eventi.Add("")
  42.             End If
  43.             If EventoLogApp.Entries(i).InstanceId.ToString = 13 Then
  44.                 Eventi.Add("------ ARRESTO SISTEMA IN EVENTO N. " & i)
  45.                 Eventi.Add(EventoLogApp.Entries(i).TimeGenerated.ToString)
  46.                 Eventi.Add(EventoLogApp.Entries(i).Source.ToString)
  47.                 Eventi.Add("ID: " & EventoLogApp.Entries(i).InstanceId.ToString)
  48.                 Eventi.Add("PC: " & EventoLogApp.Entries(i).MachineName.ToString)
  49.                 Eventi.Add("")
  50.             End If
  51.         Next
  52.         Label1.Text = EventoLogApp.Entries.Count & "/" & EventoLogApp.Entries.Count
  53.         ' visualizzazione veloce
  54.         RiTeBo.Lines = Eventi.ToArray
  55.     End Sub
  56.  
  57.     Private Sub Button2_Click(sender As Object, e As EventArgs)
  58.         Dim EventoLogApp As New System.Diagnostics.EventLog("System")
  59.         Eventi.Clear()
  60.         RiTeBo.Clear()
  61.         ' ricerca dalla fine, per trovare più velocemente gli ultimi avvii, ID 1 = TroubleShooter (si genera più volte durante l'avvio di win)
  62.         For i = EventoLogApp.Entries.Count - 1 To 1 Step -1
  63.             Label1.Text = i
  64.             Label1.Refresh()
  65.             If EventoLogApp.Entries(i).InstanceId = 1 Then
  66.                 Eventi.Add("------ ULTIMO AVVIO WIN DOPO SOSPENSIONE, EVENTO N. " & i)
  67.                 Eventi.Add(EventoLogApp.Entries(i).TimeGenerated.ToString)
  68.                 If OraACCENSIONE Is Nothing Then
  69.                     OraACCENSIONE = EventoLogApp.Entries(i).TimeGenerated
  70.                     Timer1.Enabled = True
  71.                 End If
  72.                 Eventi.Add(EventoLogApp.Entries(i).Source.ToString)
  73.                 Eventi.Add("ID: " & EventoLogApp.Entries(i).InstanceId.ToString)
  74.                 Eventi.Add("PC: " & EventoLogApp.Entries(i).MachineName.ToString)
  75.                 Eventi.Add("PC: " & EventoLogApp.Entries(i).Message)
  76.                 Eventi.Add("")
  77.             End If
  78.             If EventoLogApp.Entries(i).InstanceId = 12 Then
  79.                 Eventi.Add("------ ULTIMO AVVIO DOPO ARRESTO SISTEMA, EVENTO N. " & i)
  80.                 Eventi.Add(EventoLogApp.Entries(i).TimeGenerated.ToString)
  81.                 OraACCENSIONE2 = EventoLogApp.Entries(i).TimeGenerated
  82.                 Timer1.Enabled = True
  83.                 Eventi.Add(EventoLogApp.Entries(i).Source.ToString)
  84.                 Eventi.Add("ID: " & EventoLogApp.Entries(i).InstanceId.ToString)
  85.                 Eventi.Add("PC: " & EventoLogApp.Entries(i).MachineName.ToString)
  86.                 Eventi.Add("")
  87.                 Exit For ' al primo ID 12 trovato, ricerca interrotta
  88.             End If
  89.         Next
  90.         RiTeBo.Lines = Eventi.ToArray
  91.     End Sub
  92.  
  93.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
  94.         ' preparazione del Form
  95.         Button1.Text = "CERCA tutti"
  96.         Button1.Location = New Point(10, 10)
  97.         AddHandler Button1.Click, AddressOf Button1_Click
  98.         Me.Controls.Add(Button1)
  99.         Button2.Text = "CERCA ultima accensione"
  100.         Button2.Location = New Point(90, 10)
  101.         Button2.Width = 150
  102.         AddHandler Button2.Click, AddressOf Button2_Click
  103.         Me.Controls.Add(Button2)
  104.         Label1.Location = New Point(240, 16)
  105.         Label1.AutoSize = True
  106.         Me.Controls.Add(Label1)
  107.         Label2.Location = New Point(240, 30)
  108.         Label2.AutoSize = True
  109.         Me.Controls.Add(Label2)
  110.         RiTeBo.Location = New Point(10, 50)
  111.         Me.Controls.Add(RiTeBo)
  112.         Me.Size = New Size(400, 500)
  113.         Me.Text = "EVENTI ON/OFF - C.B."
  114.         Timer1 = New Timer
  115.         AddHandler Timer1.Tick, AddressOf timer1_tick
  116.         Timer1.Interval = 1000
  117.         Timer1.Enabled = False
  118.     End Sub
  119.  
  120.     Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged
  121.         RiTeBo.Size = New Size(Me.Width - 36, Me.Height - 100)
  122.     End Sub
  123.  
  124.     Private Sub timer1_tick(sender As Object, e As EventArgs)
  125.         Label1.Text = Now.Subtract(OraACCENSIONE).ToString("G")
  126.         Label2.Text = Now.Subtract(OraACCENSIONE2).ToString("G")
  127.     End Sub
  128. End Class


Ultima modifica effettuata da Carlo il 07/03/2020 alle 13:49


in programmazione tutto è permesso
PM Quote
Avatar
alip1 (Normal User)
Pro


Messaggi: 139
Iscritto: 12/08/2019

Segnala al moderatore
Postato alle 15:15
Sabato, 07/03/2020
Testo quotato

Postato originariamente da alip1:

Grazie domattina vedrò meglio l'impostazione risparmio energia e riproverò. Poi farò sapere



In effetti come pensava Carlo era in sospensione... ora ho messo "Arresta il sistema" e quando riparte ho:

utilizzando ID=12

------ ULTIMA ACCENSIONE IN EVENTO N. 32232
07/03/2020 15:01:46
Microsoft-Windows-UserModePowerService
ID: 12
PC: ALNB02

utilizzando ID=1 ho:

------ ULTIMA ACCENSIONE IN EVENTO N. 32248
07/03/2020 15:03:33
Microsoft-Windows-Power-Troubleshooter
ID: 1
PC: ALNB02

Volevo anche sottolineare che con gli altri codici il problema non si risolve, per cui nel ringraziare tutti consentitemi un ringraziamento particolare a Carlo.
Buon lavoro e buon week end a tutti:hail::k:

Ultima modifica effettuata da alip1 il 07/03/2020 alle 15:17
PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1344
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 17:49
Sabato, 07/03/2020
Bene, con arresto sistema impiegherà un po' di più a partire, ma quando si vuole la sospensione basta attivarla chiudendo il coperchio del portatile, e quando si vuole arrestare veramente windows, usare il pulsante di accensione.
Ho controllato l'ID 1 si attiva due o tre volte mentre si avvia Windows, penso che può essere tranquillamente usato per calcolare da quanto tempo è acceso il PC anche dopo sospensione.

Ultima modifica effettuata da Carlo il 07/03/2020 alle 17:50


in programmazione tutto è permesso
PM Quote
Avatar
alip1 (Normal User)
Pro


Messaggi: 139
Iscritto: 12/08/2019

Segnala al moderatore
Postato alle 18:47
Sabato, 07/03/2020
Testo quotato

Postato originariamente da Carlo:

Bene, con arresto sistema impiegherà un po' di più a partire, ma quando si vuole la sospensione basta attivarla chiudendo il coperchio del portatile, e quando si vuole arrestare veramente windows, usare il pulsante di accensione.
Ho controllato l'ID 1 si attiva due o tre volte mentre si avvia Windows, penso che può essere tranquillamente usato per calcolare da quanto tempo è acceso il PC anche dopo sospensione.



Grazie:k::asd:

PM Quote
Pagine: [ 1 2 3 ] Precedente | Prossimo