diff --git a/App_Code/ClsPaginas.vb b/App_Code/ClsPaginas.vb index 7aa2895e1..75dad3cae 100644 --- a/App_Code/ClsPaginas.vb +++ b/App_Code/ClsPaginas.vb @@ -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 diff --git a/App_Code/ThreadSafeRandom.vb b/App_Code/ThreadSafeRandom.vb index 825913ccb..fc20be441 100644 --- a/App_Code/ThreadSafeRandom.vb +++ b/App_Code/ThreadSafeRandom.vb @@ -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 \ No newline at end of file