E
eBob.com
In my class which contains the code for my worker thread I have ...
Public MustInherit Class Base_Miner
#Region " Delegates for accessing main UI form "
Delegate Sub DelegAddProgressBar(ByVal uiform As Form1, ByRef si As
MTCC02.Form1.SiteRunOpts, _
ByVal numitems As Integer)
#End Region
Public globalinf As MTCC02.Form1.GlobalRunOpts
Public siteinf As MTCC02.Form1.SiteRunOpts
....
The constructor for this class does ...
Public Sub New(ByVal url As String, ByVal globalinfo As
MTCC02.Form1.GlobalRunOpts, _
ByRef siteinfo As MTCC02.Form1.SiteRunOpts)
....
globalinf = globalinfo 'save for LoadTextFile sub
siteinf = siteinfo 'save for LoadTextFile sub
It's the siteinf structure which I think is central to the problem I am
looking for some help with. What I think I am doing here is making the
structure available to all the methods of the Base_Miner class and all
classes which inherit from it. Right?
Still in the constuctor I do ...
Dim AddProgBar As DelegAddProgressBar = New DelegAddProgressBar(AddressOf
MTCC02.Form1.AddProgressBar)
globalinf.UIFormInst.Invoke(AddProgBar, New Object() {globalinf.UIFormInst,
siteinfo, NextDetailUrlsIndex})
Here in the constructor I think that I can use siteinf and siteinfo
interchangebly. Right?
On return from the Invoke the debugger shows that the "progbarProgress"
field of both siteinf and siteinfo is Nothing. ?!?!?
In my Form1 class, and this code is runs on my main/UI thread, I have ...
Public Shared Sub AddProgressBar(ByVal uiform As Form1, ByRef si As
SiteRunOpts, ByVal numitems As Integer)
si.progbarProgress = New ProgressBar
With si.progbarProgress
.Width = numitems \ 2
.Maximum = numitems
.Location = New Point(progbarProgress_xloc, si.yloc)
.Step = 1
End With
uiform.Controls.Add(si.progbarProgress)
End Sub 'AddProgressBar
At the end of this Sub, when I use the debugger and check the si argument,
the "progbarProgress" field is not Nothing and looks reasonable (to me!,
which is maybe not saying much). Also,the progressbar does get created - I
see it appear on the UI form. But back in the worker thread which is
running the Base_Miner code and which issued the Invoke which caused the
AddProgressBar code to be run the SiteRunOpts structure has Nothing in the
progbarProgress field.
What's going on here? Did the worker thread get its own copy of the
SiteRunOpts structure it was passed? How do I fix this?
Incidentally, does it matter is a structure is passed ByRef or ByVal so long
as you are only accessing fields within the structure? I think I've been
told it does not but earlier when I was passing the SiteRunOpts argument
ByVal I was wondering about that.
This has got me most frustrated, so I will be most grateful for any help.
Bob
Public MustInherit Class Base_Miner
#Region " Delegates for accessing main UI form "
Delegate Sub DelegAddProgressBar(ByVal uiform As Form1, ByRef si As
MTCC02.Form1.SiteRunOpts, _
ByVal numitems As Integer)
#End Region
Public globalinf As MTCC02.Form1.GlobalRunOpts
Public siteinf As MTCC02.Form1.SiteRunOpts
....
The constructor for this class does ...
Public Sub New(ByVal url As String, ByVal globalinfo As
MTCC02.Form1.GlobalRunOpts, _
ByRef siteinfo As MTCC02.Form1.SiteRunOpts)
....
globalinf = globalinfo 'save for LoadTextFile sub
siteinf = siteinfo 'save for LoadTextFile sub
It's the siteinf structure which I think is central to the problem I am
looking for some help with. What I think I am doing here is making the
structure available to all the methods of the Base_Miner class and all
classes which inherit from it. Right?
Still in the constuctor I do ...
Dim AddProgBar As DelegAddProgressBar = New DelegAddProgressBar(AddressOf
MTCC02.Form1.AddProgressBar)
globalinf.UIFormInst.Invoke(AddProgBar, New Object() {globalinf.UIFormInst,
siteinfo, NextDetailUrlsIndex})
Here in the constructor I think that I can use siteinf and siteinfo
interchangebly. Right?
On return from the Invoke the debugger shows that the "progbarProgress"
field of both siteinf and siteinfo is Nothing. ?!?!?
In my Form1 class, and this code is runs on my main/UI thread, I have ...
Public Shared Sub AddProgressBar(ByVal uiform As Form1, ByRef si As
SiteRunOpts, ByVal numitems As Integer)
si.progbarProgress = New ProgressBar
With si.progbarProgress
.Width = numitems \ 2
.Maximum = numitems
.Location = New Point(progbarProgress_xloc, si.yloc)
.Step = 1
End With
uiform.Controls.Add(si.progbarProgress)
End Sub 'AddProgressBar
At the end of this Sub, when I use the debugger and check the si argument,
the "progbarProgress" field is not Nothing and looks reasonable (to me!,
which is maybe not saying much). Also,the progressbar does get created - I
see it appear on the UI form. But back in the worker thread which is
running the Base_Miner code and which issued the Invoke which caused the
AddProgressBar code to be run the SiteRunOpts structure has Nothing in the
progbarProgress field.
What's going on here? Did the worker thread get its own copy of the
SiteRunOpts structure it was passed? How do I fix this?
Incidentally, does it matter is a structure is passed ByRef or ByVal so long
as you are only accessing fields within the structure? I think I've been
told it does not but earlier when I was passing the SiteRunOpts argument
ByVal I was wondering about that.
This has got me most frustrated, so I will be most grateful for any help.
Bob