Variable values collision in multiuser environment

  • Thread starter Thread starter Manuel Arroba
  • Start date Start date
M

Manuel Arroba

I had the idea that two users code are being run by two different
instancies, so from the variable values point of view they are
complete independent.

I have an asp.net that calls a module rutine.

When there are two users accessing to the module rutine, looks like
asp.net is sharing variable values. For example, in one point I check
the size of the table (from debug for example I now is 3) but is
reporting an incorrect size (let says 5 that comes from the table of
the second user).

The question I am not sure if this is wad or I am doing something
wrong.

Thanks in advance...
 
Manuel Arroba said:
I had the idea that two users code are being run by two different
instancies, so from the variable values point of view they are
complete independent.

I have an asp.net that calls a module rutine.

When there are two users accessing to the module rutine, looks like
asp.net is sharing variable values. For example, in one point I check
the size of the table (from debug for example I now is 3) but is
reporting an incorrect size (let says 5 that comes from the table of
the second user).

The question I am not sure if this is wad or I am doing something
wrong.

One thing you're doing wrong is not giving us much detail. :-)

Where are the variables you believe are being shared? I bet they are
module-level variables, in which case they will be shared, as there is only
one instance of the module, not one per page request.
 
Hi John thank you very much for your answer...

I did not post any code because I think it was a general question.

I have a page that is calling a rutine in a module file (.vb).

Public Structure DatosRutaConDatos
Public TodoOk As Boolean
Public tabla As DataTable
Public TextoError As String
End Structure
Module RutinasSincronizacion
Dim InstanciaDatosRuta As New DatosRuta()
Public Function BuscaInfo(ByVal tb As DataTable, ByVal Centro As
String) As DatosRutaConDatos
....
end function
...
end module


The problem arises when two users (two pages) call the same rutine
(BuscaInfo) at the same time. Some variables look that are not shared,
but I have problems with the InstanciaDatosRuta.

I had the idea that any code should not be shared.

Does it mean that we cannot use modules files ?... it looks a bit
strange.

Would you mind to confirm this point ?...
Thanks again... have a nice day
Manuel Arroba
 
Manuel Arroba said:
Hi John thank you very much for your answer...

I did not post any code because I think it was a general question.

I have a page that is calling a rutine in a module file (.vb).

Public Structure DatosRutaConDatos
Public TodoOk As Boolean
Public tabla As DataTable
Public TextoError As String
End Structure
Module RutinasSincronizacion
Dim InstanciaDatosRuta As New DatosRuta()
Public Function BuscaInfo(ByVal tb As DataTable, ByVal Centro As
String) As DatosRutaConDatos
...
end function
..
end module


The problem arises when two users (two pages) call the same rutine
(BuscaInfo) at the same time. Some variables look that are not shared,
but I have problems with the InstanciaDatosRuta.

I had the idea that any code should not be shared.

Does it mean that we cannot use modules files ?... it looks a bit
strange.

Manuel, InstanciaDatosRuta will be shared by all users of the module. What
would have caused a new copy of InstanciaDatosRuta to be created?

You should probably avoid modules when working in VB.NET. They are a pre-OO
construct.

If you want a separate instance of InstanciaDatosRuta to exist per user,
then you're going to have to explicitly create the separate instance
somehow. For instance:

Public Structure DatosRutaConDatos
Public TodoOk As Boolean
Public tabla As DataTable
Public TextoError As String
End Structure
Public Class RutinasSincronizacion
Private InstanciaDatosRuta As New DatosRuta()
Public Function BuscaInfo(ByVal tb As DataTable, ByVal Centro As
String) As DatosRutaConDatos
....
end function
...
End Class


You will need to have some piece of code create an instance of the class
RutinasSincronizacion. Perhaps such an instance would be stored in Session:

If Session("RutinasSincronizacion") Is Nothing Then
Session("RutinasSincronizacion") = New RutinasSincronizacion()
End If

Dim RS As RutinasSincronizacion =
DirectCast(Session("RutinasSincronizacion"), RutinasSincronizacion)

Dim DRCD As DatosRutaConDatos = RS.BuscaInfo(tb, "centro")
 
Hi John, thanks for you answer and your code sugestion..

I only can help you with you spanish.. :-)

Ruta is like "path". In this case is the path that follow some
products in a factory...

Thanks again, and have a nice day...
 
Manuel Arroba said:
Hi John, thanks for you answer and your code sugestion..

I only can help you with you spanish.. :-)

Ruta is like "path". In this case is the path that follow some
products in a factory...

Thanks, this shows I'm getting old. I used to know "ruta" (which is akin to
"route" in English).
 
Back
Top