'New' not behaving as exprected. Advice needed urgently.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi

Long Post - Please read to end to understand my question.

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


.



Relevant Pages

  • RE: New not behaving as exprected. Advice needed urgently.
    ... > Public Shared Sub AcceptCallback ... > Public Class BarCodeSizeData ... > Public Sub Add(ByVal SizeData As BarCodeSizeData) ... > Public Property ItemAs BarCodeSizeData ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Sorting Possible?
    ... public class PersonCollection: ... Public Property Name ... Public Class PersonCollection: Inherits CollectionBase ... Public Sub add ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: How to keep track of changes of an object???
    ... Option Strict Off ... Public Class LogFile ... Public Property Weight() As Byte ... Public Sub New ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Help Please - sorting array of objects
    ... Public Class Form1 ... Public Sub dumpbooks ... Public Sub New(ByVal author As String, ... Public Property AuthorAs String ...
    (microsoft.public.dotnet.languages.vb)
  • RE: New not behaving as exprected. Advice needed urgently.
    ... Public Class StateObject ... >> Public Shared Sub AcceptCallback ... >> Public Class CollectData. ... >> Public Sub Add(ByVal SizeData As BarCodeSizeData) ...
    (microsoft.public.dotnet.languages.vb)