tcss
New member
Hi
Please read entire post before replying.
Is there a better way to do this?
I am writing a telnet server in VB.net
(code samples lower down)
I connect two hyperterm sessions to the code. (2 telnet sessions.)
The state object created when the socket connects as such
Public Shared Sub AcceptCallback(ByVal ar As IAsyncResult)
Dim State As New StateObject()
State.sb = ""
State.UserData = New StateObject.CollectData()
....
end
This triggers the new statement for
Public Class CollectData.
When I examine the memory of these items (using memory window)
they are assigned "nothing" before the call new new.
After the call to new the are assigned the same memory address for both threads.
Can anyone please tell me why this is happening. The other items in the structer
StockTakeNo
BranchCodeId
StockRoomId
UserName
Password
all appear correct and contail the data givvent to them by the new session.
The collections (having the same address in both threads) have a combined pool of information. This is breaking the app as each session deals with and writes different data to the database.
Thread 1
colBarCodeSize 0x0210A794
colBarCode 0x0210A790
Thread 2
colBarCodeSize 0x0210A794
colBarCode 0x0210A790
Other code can be posted as required. Any mindfull insight into this will be appretiated.
The following are structures extracted from the code.
Public Class BarCodeSizeData
Public BarCodePrdSizeID As Long
Public BarCodeQty As Integer
End Class
Public Class BarCodeData
Public BarCodeString As String
Public BarCodePrdColourID As Long
Public TotPrdCodeQty As Integer
Public ArrLen As Integer
Public aListOfItems(50) As Integer
End Class
Public Class StateObject
Public Class CollectData
Public StockTakeNo As String
Public BranchCodeId As Long
Public StockRoomId As Long
Public UserName As String
Public Password As String
Public BinNo As String
Public ToCount As String
Public Counter As Integer
Public Shared colBarCode As BarCodeDataCollection
Public Shared colBarCodeSize As BarCodeSizeCollection
Sub New()
colBarCode = New BarCodeDataCollection()
colBarCodeSize = New BarCodeSizeCollection()
End Sub
End Class
Public Class BarCodeSizeCollection
Inherits System.Collections.CollectionBase
Public Sub Add(ByVal SizeData As BarCodeSizeData)
' Invokes Add method of the List object to add a widget.
List.Add(SizeData)
End Sub
Public Sub Remove(ByVal index As Integer)
' Check to see if there is a widget at the supplied index.
If index > Count - 1 Or index < 0 Then
Else
List.RemoveAt(index)
End If
End Sub
Public Property Item(ByVal index As Integer) As BarCodeSizeData
Get
' The appropriate item is retrieved from the List object and
' explicitly cast to the Widget type, then returned to the
' caller.
Return CType(List.Item(index), BarCodeSizeData)
End Get
Set(ByVal Value As BarCodeSizeData)
List.Item(index) = Value
End Set
End Property
end class
Public Class BarCodeDataCollection
Inherits System.Collections.CollectionBase
Public Sub Add(ByVal CodeData As BarCodeData)
List.Add(CodeData)
End Sub
Public Sub Remove(ByVal index As Integer)
' Check to see if there is a widget at the supplied index.
If index > Count - 1 Or index < 0 Then
Else
List.RemoveAt(index)
End If
End Sub
Public Property Item(ByVal index As Integer) As BarCodeData
Get
' The appropriate item is retrieved from the List object and
' explicitly cast to the Widget type, then returned to the
' caller.
Return CType(List.Item(index), BarCodeData)
End Get
Set(ByVal Value As BarCodeData)
List.Item(index) = Value
End Set
End Property
End Class
TCSS
Please read entire post before replying.
Is there a better way to do this?
I am writing a telnet server in VB.net
(code samples lower down)
I connect two hyperterm sessions to the code. (2 telnet sessions.)
The state object created when the socket connects as such
Public Shared Sub AcceptCallback(ByVal ar As IAsyncResult)
Dim State As New StateObject()
State.sb = ""
State.UserData = New StateObject.CollectData()
....
end
This triggers the new statement for
Public Class CollectData.
When I examine the memory of these items (using memory window)
they are assigned "nothing" before the call new new.
After the call to new the are assigned the same memory address for both threads.
Can anyone please tell me why this is happening. The other items in the structer
StockTakeNo
BranchCodeId
StockRoomId
UserName
Password
all appear correct and contail the data givvent to them by the new session.
The collections (having the same address in both threads) have a combined pool of information. This is breaking the app as each session deals with and writes different data to the database.
Thread 1
colBarCodeSize 0x0210A794
colBarCode 0x0210A790
Thread 2
colBarCodeSize 0x0210A794
colBarCode 0x0210A790
Other code can be posted as required. Any mindfull insight into this will be appretiated.
The following are structures extracted from the code.
Public Class BarCodeSizeData
Public BarCodePrdSizeID As Long
Public BarCodeQty As Integer
End Class
Public Class BarCodeData
Public BarCodeString As String
Public BarCodePrdColourID As Long
Public TotPrdCodeQty As Integer
Public ArrLen As Integer
Public aListOfItems(50) As Integer
End Class
Public Class StateObject
Public Class CollectData
Public StockTakeNo As String
Public BranchCodeId As Long
Public StockRoomId As Long
Public UserName As String
Public Password As String
Public BinNo As String
Public ToCount As String
Public Counter As Integer
Public Shared colBarCode As BarCodeDataCollection
Public Shared colBarCodeSize As BarCodeSizeCollection
Sub New()
colBarCode = New BarCodeDataCollection()
colBarCodeSize = New BarCodeSizeCollection()
End Sub
End Class
Public Class BarCodeSizeCollection
Inherits System.Collections.CollectionBase
Public Sub Add(ByVal SizeData As BarCodeSizeData)
' Invokes Add method of the List object to add a widget.
List.Add(SizeData)
End Sub
Public Sub Remove(ByVal index As Integer)
' Check to see if there is a widget at the supplied index.
If index > Count - 1 Or index < 0 Then
Else
List.RemoveAt(index)
End If
End Sub
Public Property Item(ByVal index As Integer) As BarCodeSizeData
Get
' The appropriate item is retrieved from the List object and
' explicitly cast to the Widget type, then returned to the
' caller.
Return CType(List.Item(index), BarCodeSizeData)
End Get
Set(ByVal Value As BarCodeSizeData)
List.Item(index) = Value
End Set
End Property
end class
Public Class BarCodeDataCollection
Inherits System.Collections.CollectionBase
Public Sub Add(ByVal CodeData As BarCodeData)
List.Add(CodeData)
End Sub
Public Sub Remove(ByVal index As Integer)
' Check to see if there is a widget at the supplied index.
If index > Count - 1 Or index < 0 Then
Else
List.RemoveAt(index)
End If
End Sub
Public Property Item(ByVal index As Integer) As BarCodeData
Get
' The appropriate item is retrieved from the List object and
' explicitly cast to the Widget type, then returned to the
' caller.
Return CType(List.Item(index), BarCodeData)
End Get
Set(ByVal Value As BarCodeData)
List.Item(index) = Value
End Set
End Property
End Class
TCSS