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:
@@ -45,7 +45,6 @@ Public Class ClsPaginas
|
||||
End Property
|
||||
|
||||
#Region "Propiedades"
|
||||
Private Shared ReadOnly Property Rand As New ThreadSafeRandom()
|
||||
Private Property SubReportData As Modelos.MSubReportData
|
||||
Get
|
||||
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 = "")
|
||||
Dim page As Page = TryCast(HttpContext.Current.CurrentHandler, Page)
|
||||
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
|
||||
Public Sub TabEnabled(Tab As System.Web.UI.HtmlControls.HtmlAnchor, Valor As Boolean)
|
||||
If Valor Then
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
Imports System.Threading
|
||||
|
||||
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 LocalRandom As New ThreadLocal(Of Random)(Function()
|
||||
|
||||
SyncLock GlobalRandom
|
||||
Return New Random(GlobalRandom.Next())
|
||||
End SyncLock
|
||||
End Function)
|
||||
|
||||
Function [Next](Optional min As Integer = 0, Optional max As Integer = Integer.MaxValue) As Integer
|
||||
Public Shared Function [Next](Optional min As Integer = 0, Optional max As Integer = Integer.MaxValue) As Integer
|
||||
Return LocalRandom.Value.Next(min, max)
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user