[dba-VB] Background worker threads

Charlotte Foust cfoust at infostatsystems.com
Wed Apr 30 12:28:02 CDT 2008


I'm sorry, John, I missed the contextt of your question.   We don't use
background workers that way, so I don't have an answer for you.

Charlotte 

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Wednesday, April 30, 2008 9:05 AM
To: Discussion concerning Visual Basic and related programming issues.
Subject: Re: [dba-VB] Background worker threads

Charlotte,

Could you be a little more verbose?

I have spent about 6 hours now Googling and reading EXACTLY the same
(though written by different authors) code "the button starts the
thread, the thread increments the number, the thread raises its event
and passes a "percent done" to the form where it is used to update a
progress bar".

Give me a break!

To be honest I am astonished that FORTY different people thought that it
was necessary to publish identical content articles.  None of which
answers either of my questions.

I have a class.

The class has TWO BackgroundWorker objects defined Withevents.

bgwParseData is running a function that creates a class to load data
from a SQL server, and once loaded, parse that data.  The basic code WAS
working before I carved it out into a worker.

bgwUpdateData is running a method of a class that updates data back to
SQL Server.  The basic code WAS working before I carved it out into a
worker.

So... a single data class, two methods, one reads / parses the data in
an ADO DataTable, the second writes the datatable back to SQL Server.

Two threads, bgwParseData generates the data class and calls the
read/Parse method, then stores the class in a collection.  bgwUpdateData
watches the collection, pulls the class out and calls the update method.

Or that is the theory.  I have asked whether it is legal for one
background worker to write to a collection while a second background
worker reads that collection.  No answer so far.

The second issue is how can bgwParseData update THREE different text
boxes on the main form.  All of the examples show a cute "progress bar".

  I don't want a progress bar, I want THREE text boxes to display data
from the process running in the background worker.

I know that I can create events and raise them, and I DID THAT before I
started converting to backgroundworkers.  That was easy.  HOWEVER the
way I read it I can't raise those same events from the BackgroundWorker
thread because the event sink updates a physical control on the form,
and that is a no-no from a thread.

Unfortunately, as always happens with the books, they don't discuss
anything more complicated than incrementing a number and passing that
number back to a progress bar on the form.  I have seen that (almost)
identical code in probably FORTY different articles on using the
backgroundworker.  All saying EXACTLY the same, useless (to me) thing.

Sigh.

John W. Colby
www.ColbyConsulting.com


Charlotte Foust wrote:
> You can create your own events with whatever parameters you want and 
> raise those.  Just Dim Public Event Whatever(parameter)  Then raise it

> as needed.
> 
> Charlotte Foust
_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com





More information about the dba-VB mailing list