Proper multiuser web coding
I am trying to get myself out of the dark ages and convert our Windows Desktop Apps to the web (VB.2015).
I have received some code from a developer to do this and I am not sure that it is correct for multi-users.
Given the below code. It appears to me that the AddInvoice being shared the variables both in the parameters and the inline definitions would not be unique since the class has not
Button event calls the class method fileImporter.readIt(
Code:
Public Class Importer
Inherits BasePage
...
Protected Sub UploadBtn_Click(sender As Object, e As EventArgs)
If Not fileReader.readIt(strPath, dsData, pOutReason) Then
messagesList.Add("File Name : " + FileUpLoad1.FileName.ToLower() + pOutReason) : GoTo ExitFunction
Else
fileImporter.readIt(strPath, profile.OAuthAccessToken, profile.OAuthAccessTokenSecret, profile.RealmId, dsData, messagesList, "Read IIF file")
End If
End Sub
End Class
But the class is never instantiated but just called so a new copy of the class is not created and thus only one set of variables in the machine.
Code:
Public Class FileImpoter(worksheetName As String, OAuthAccessToken As String, OAuthAccessTokenSecret As String, realmId As String, dsData As DataSet, ByRef messagesList As List(Of String), Optional ByRef pOutReason As String = "") As Boolean
...
Public Function readIt(...)
...
AddInvoice(OAuthAccessToken, OAuthAccessTokenSecret, realmId, messagesList, "Add Invoice", dsData)
...
End Function
...
Private Shared Function AddInvoice(...)
Dim FunRC As Boolean = False
Dim Ern As Integer
Dim Erd As String
If ds1.Tables(0) IsNot Nothing AndAlso ds1.Tables(0).Rows.Count > 0 Then
For i = 0 To ds1.Tables(0).Rows.Count - 1
Dim row = ds1.Tables(0).Rows(i)
...
Next
endif
...
End Function
End Class
So is the code incorrect? or do I have more to learn???
Re: Proper multiuser web coding
Well, it could be both, of course. You ALWAYS have more to learn, regardless of whether this code is correct.
However, you may be thinking about this wrong. In most cases, any individual viewing the web page will be independent of any other person viewing the web page. So, it's quite likely that every user of the process is sharing the object, but there is only ever one user of the process. Each user gets their own process independent of any other.
I guess I'm not quite sure about some of the architecture here, so I still have stuff to learn, as well, but I believe that there will be one instance of the class per user of the service. That could be wrong, though, and there's enough missing from that class that I'm not certain. If this is a process on a web server, then it should be per instance. If you are creating your own server, then it depends on how the server is handling requests. Normally, each request would be spun off to its own thread, but you don't HAVE to do it that way, in which case you could get interactions.
The class does have to be instantiated somewhere, though, since it appears to be calling non-shared members.