VB Thread

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Function CalcularFibonacci(ByVal n As Integer,

ByVal worker As BackgroundWorker,


ByVal e As DoWorkEventArgs) As Long
'No permitimos valores superiores a 91 ni inferiores a 9
If n < 0 OrElse n > 91 Then
Throw New ArgumentException( _
"value must be >= 0 and <= 91", "n")
End If
Dim result As Long = 0
iteraciones = iteraciones + 1
'Si el usuario ha pulsado el botn cancelar abortar la operacin
If worker.CancellationPending Then
e.Cancel = True
Else
If n < 2 Then
result = 1
Else
result = CalcularFibonacci(n - 1, worker, e) + _
CalcularFibonacci(n - 2, worker, e)
End If
'Establecemos el % de progreso realizado del total de la tarea
Dim percentComplete As Integer = _
CSng(n) / CSng(numberToCompute) * 100
If percentComplete > highestPercentageReached Then
highestPercentageReached = percentComplete
worker.ReportProgress(percentComplete)
End If
End If
Return result
End Function

You might also like