Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Dotinho

Rotina de try...end try...

Recommended Posts

Dotinho

Ora digam-me lá se isto não funciona? e porque? ora se falhar ao criar os performance conters, dá o erro e deve sair. Ou estou--me a esquecer de aguma coisa?

   Private Sub S_Perf()
        Dim pf1 As PerformanceCounter = Nothing : Dim pf2 As PerformanceCounter = Nothing
        Dim d1, d2 As String : d1 = _ori.Substring(0, 2) : d2 = _des.Substring(0, 2)
        Dim digual As Boolean : digual = (d1 = d2)
        Dim ar1 As New Queue : Dim ar2 As New Queue
        If String.Equals(d1, d2) = False Then
            Try
                pf1 = New PerformanceCounter("Disco lógico", "% tempo de disco", d1)
                pf2 = New PerformanceCounter("Disco lógico", "% tempo de disco", d2)
            Catch ex As Exception
                Exit Sub
            End Try
        Else
            Try
                pf1 = New PerformanceCounter("Disco lógico", "% tempo de disco", d1)
            Catch ex As Exception
                Exit Sub
            End Try
        End If
        Thread.Sleep(250)

        While _cancel = False
            Dim perc1, perc2 As Integer
            If Not pf1 Is Nothing Then
                ar1.Enqueue(pf1.NextValue)
                If ar1.Count > 10 Then : ar1.Dequeue() : End If
                perc1 = FX_CalcMedia(ar1)
            Else : perc1 = 0 : End If

            If Not pf2 Is Nothing Then
                ar2.Enqueue(pf2.NextValue)
                If ar2.Count > 10 Then : ar2.Dequeue() : End If
                perc2 = FX_CalcMedia(ar2)
            Else : perc2 = 0 : End If

            UPD_Perf.BeginInvoke(d1, perc1, d2, perc2, Nothing, Nothing)
           
            Thread.Sleep(150)
        End While
        UPD_Perf.BeginInvoke(" ", 0, " ", 0, Nothing, Nothing)
    End Sub

cmps


Luis Lourenço

Share this post


Link to post
Share on other sites
Weasel

Mete assim

Catch ex As Exception
  MsgBox(ex.ToString)
  Exit Sub
End Try

Ao menos assim vês qual foi o erro


Knowledge to the masses


Share this post


Link to post
Share on other sites
ceptrus

e porque nao meteres apenas um try .. catch

e todo o código que tiveres vai lá dentro, tornas o código mais legivel e faz a mesma coisa k tens feito.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.