
Passing values between running threads ?
Have written a program to read data from a couple hundred Excel
files. (inVB.Net)
The first time the program is run, this is done in the form load
event. Because this process takes several minutes, the user spend what seems
like forever sitting and staring at a blank screen.
I decided that I wanted to add another form which would display a
progress bar while this load event was taking place. Spent the past several
weeks trying to beat the concept of threading into my thick skull. Thought I
understood it, but I just don't know how to go about doing what i want to do
for this application. The tutorials and examples that I've found really
don't cover what I want to do.
I already have the loop written that gets the data from Excel, so I
was hoping that I could leave that as it was, while passing the required
variables into a component, where another thread is started to load the
frmProgress_Bar. To try and simulate what I wanted to do I wrote a
simplified version of this:
1) frmMain Load event calls a subprogram (Sub Index_Count) which indexes
an accumulator thru a timer to slow the loop down
Component1.gsngCount = sngCount
Component1.gsngEndVal = sngEndVal
Passes my values to the component. This loops with the count,
with the mistaken thought that it would update the value in the component
continually while counting
2) A Thread which is defined in my component is called (from Sub
Index_Count) , which starts the progress bar form (On the first loop only)
3) The form load event for this form starts another thread, also defined
in the component
This thread performs a RaiseEvent to pass the gsngCount and
gsngEndVal values thru a CountHandler in my ProgressBar form (which I was
hoping would continually update with the loops from
the first form load procedure (Sub Index_Count) which are still going on )
4) BeginInvoke then passes this value thru a delegate into the sub which
updates my Progress bar
I believe I can see why this isn't working. I just can come up with a
method that will make it work. (Yeah, I know that your probably thinking -
What the Hell is he doing? - But it's all I could come up with!)
Could someone please tell me what I need to be doing - I'm totally lost
here!
Or maybe direct me to a code sample. (I found a sample that does exactly
what I'm looking for, but unfortunately it was in C# and I couldn't quite
follow it {ASyncCalc_Pi})