ClsPaginas: ThreadSafeRandom es estático

-En la conversión de C# a VB.NET se me pasó que la clase es completamente estática
 y es innecesario instanciarla. Basta con llamar a ThreadSafeRandom.Next()
 Lo que es mejor, así queda mas explícito.
This commit is contained in:
MLopez
2023-02-01 20:23:46 -07:00
parent 99facf88ad
commit ed012cb59b
2 changed files with 5 additions and 5 deletions

View File

@@ -45,7 +45,6 @@ Public Class ClsPaginas
End Property End Property
#Region "Propiedades" #Region "Propiedades"
Private Shared ReadOnly Property Rand As New ThreadSafeRandom()
Private Property SubReportData As Modelos.MSubReportData Private Property SubReportData As Modelos.MSubReportData
Get Get
Return If(IsNothing(ViewState("SubReportData")), Nothing, DirectCast(ViewState("SubReportData"), Modelos.MSubReportData)) Return If(IsNothing(ViewState("SubReportData")), Nothing, DirectCast(ViewState("SubReportData"), Modelos.MSubReportData))
@@ -6186,7 +6185,7 @@ Public Class ClsPaginas
Public Shared Sub RegistraScript(Script As String, Optional valuetick As String = "") Public Shared Sub RegistraScript(Script As String, Optional valuetick As String = "")
Dim page As Page = TryCast(HttpContext.Current.CurrentHandler, Page) Dim page As Page = TryCast(HttpContext.Current.CurrentHandler, Page)
Script = $"{Script.TrimEnd(";"c)};" 'sino trae ";" al final, se lo agregamos Script = $"{Script.TrimEnd(";"c)};" 'sino trae ";" al final, se lo agregamos
ScriptManager.RegisterStartupScript(page, page.GetType(), $"{DateTime.Now.Ticks + 1}{Rand.Next()}{valuetick}", Script, True) ScriptManager.RegisterStartupScript(page, page.GetType(), $"{DateTime.Now.Ticks + 1}{ThreadSafeRandom.Next()}{valuetick}", Script, True)
End Sub End Sub
Public Sub TabEnabled(Tab As System.Web.UI.HtmlControls.HtmlAnchor, Valor As Boolean) Public Sub TabEnabled(Tab As System.Web.UI.HtmlControls.HtmlAnchor, Valor As Boolean)
If Valor Then If Valor Then

View File

@@ -1,15 +1,16 @@
Imports System.Threading Imports System.Threading
NotInheritable Class ThreadSafeRandom NotInheritable Class ThreadSafeRandom
Private Sub New()
'Impide que se instancie la clase (equivalente a static class en C#)
End Sub
Private Shared ReadOnly GlobalRandom As New Random() Private Shared ReadOnly GlobalRandom As New Random()
Private Shared ReadOnly LocalRandom As New ThreadLocal(Of Random)(Function() Private Shared ReadOnly LocalRandom As New ThreadLocal(Of Random)(Function()
SyncLock GlobalRandom SyncLock GlobalRandom
Return New Random(GlobalRandom.Next()) Return New Random(GlobalRandom.Next())
End SyncLock End SyncLock
End Function) End Function)
Public Shared Function [Next](Optional min As Integer = 0, Optional max As Integer = Integer.MaxValue) As Integer
Function [Next](Optional min As Integer = 0, Optional max As Integer = Integer.MaxValue) As Integer
Return LocalRandom.Value.Next(min, max) Return LocalRandom.Value.Next(min, max)
End Function End Function
End Class End Class