G
Guest
I am launching a new thread from my application's main process (using VB.net
2003), and I can't get the child to receive the parameter I'm attempting to
send it in a named data slot.
The code for launching the thread:
Dim NewThread As New Thread(AddressOf LaunchCommThread)
NewThread.AllocateNamedDataSlot("Offset")
NewThread.IsBackground = True
NewThread.Name = SIMclass.SIM(1).strCtrlDesignator
NewThread.SetData(NewThread.GetNamedDataSlot("Offset"), CType(1,
Object))
NewThread.Start()
The beginning of the LaunchCommThread function:
'get thread data and controller # to use
Dim Ctrlr As Int16 'used to ID current (from data
slot)
Ctrlr =
Thread.CurrentThread.GetData(Thread.CurrentThread.GetNamedDataSlot("Offset"))
'declare per-thread variables for TCP communication
Dim address As IPAddress =
IPAddress.Parse(SIMclass.SIM(Ctrlr).strCtrlIP)
The results from the main thread:
?newThread.GetData(newThread.GetNamedDataSlot("Offset"))
Nothing
?newthread.Name
"M1C1"
The results from the child:
?thread.CurrentThread.Name
"M1C1"
?thread.CurrentThread.GetData(thread.CurrentThread.GetNamedDataSlot("Offset"))
Nothing
Strangely, this syntax works from the main thread (does anyone know why?):
?newThread.GetData(Thread.CurrentThread.GetNamedDataSlot("Offset"))
1 {Integer}
[Integer]: 1 {Integer}
Q:
1) Am I misunderstanding the purpose of named data slots?
2) Am I misusing named data slots by using one to pass a parameter?
3) Why does this code not work? I am able to place the value into the
current thread's slot but that isn't where I am directing it?
TIA
Fred B
2003), and I can't get the child to receive the parameter I'm attempting to
send it in a named data slot.
The code for launching the thread:
Dim NewThread As New Thread(AddressOf LaunchCommThread)
NewThread.AllocateNamedDataSlot("Offset")
NewThread.IsBackground = True
NewThread.Name = SIMclass.SIM(1).strCtrlDesignator
NewThread.SetData(NewThread.GetNamedDataSlot("Offset"), CType(1,
Object))
NewThread.Start()
The beginning of the LaunchCommThread function:
'get thread data and controller # to use
Dim Ctrlr As Int16 'used to ID current (from data
slot)
Ctrlr =
Thread.CurrentThread.GetData(Thread.CurrentThread.GetNamedDataSlot("Offset"))
'declare per-thread variables for TCP communication
Dim address As IPAddress =
IPAddress.Parse(SIMclass.SIM(Ctrlr).strCtrlIP)
The results from the main thread:
?newThread.GetData(newThread.GetNamedDataSlot("Offset"))
Nothing
?newthread.Name
"M1C1"
The results from the child:
?thread.CurrentThread.Name
"M1C1"
?thread.CurrentThread.GetData(thread.CurrentThread.GetNamedDataSlot("Offset"))
Nothing
Strangely, this syntax works from the main thread (does anyone know why?):
?newThread.GetData(Thread.CurrentThread.GetNamedDataSlot("Offset"))
1 {Integer}
[Integer]: 1 {Integer}
Q:
1) Am I misunderstanding the purpose of named data slots?
2) Am I misusing named data slots by using one to pass a parameter?
3) Why does this code not work? I am able to place the value into the
current thread's slot but that isn't where I am directing it?
TIA
Fred B