[dba-VB] Worker threads and class global variables

jwcolby jwcolby at colbyconsulting.com
Tue Apr 29 23:54:18 CDT 2008


Can a backgroundworker access a class global variable in the class that 
dimensions the background worker.

I have a process that will be creating data classes.  these classes will 
fill ADO data sets, modify them and then place them in a collection 
global to the class.  This same class would then dim a backgroundworker 
object.

The way I envision this working is that the backgroundworker is 
initialized and started.  It simply sits in a loop checking the class 
global collection for data class instances deposited into the collection 
by the main thread.  If a class instance is found in the thread it pulls 
it out of the collection and processes it.  This backgroundworker 
thread's job is to run the SQL Server update code in the data class 
(call a method of that class).

Somehow that backgroundworker has to be told that the main thread is 
done parsing names, ran through the entire table and is done.  So I 
thought the main thread could set a class global boolean done flag.  Or 
something.

Can I do this at all the way I am thinking?  My problem is that there is 
no way to predict which process will be faster, name parse or SQL Server 
update.  My idea was simply to use a collection to act as an interface 
between the two.  The name parser instantiates a data class which loads 
the data to be parsed into an ADO.Net datatable.  The name parser 
updates the data in the the data class.  When it is done updating the 
data it drops the class into the collection.

the backgroundworker watches the collection and when it finds a data 
class in the collection, it pulls it out and calls the update method of 
that class to process the data.  when it is done it cleans up the ADO 
objects and stores the class in another "history" collection up in the 
parse class.  The data class will have start / stop times, start / end 
PKIDs, record count etc information which will be of interest to me.

I have never used Background worker objects so I don't know whether it 
can interface in the manner described, using collections to pass objects.
-- 
John W. Colby
www.ColbyConsulting.com



More information about the dba-VB mailing list