[dba-VB] c# - controlling the run state / status of your threadedclasses

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Thu Mar 10 17:11:33 CST 2011


Hi John --

<<<
So we have a couple of "commands" (start / stop) and a few statuses
(stopped, stopping, running).
>>> 
You'd better also add 'paused' (and maybe 'pausing' and 'resuming') for your
list of states.

I must note it's not easy to "standardize" such a coding - as with every
framework/standard there immediately come non-standard situations to code
into framework/standard - that's endless story...

I have such a coding but it's rather complicated, several nesting levels
etc.etc. - and it was programmed for a customer, I have reused it already in
three projects of that customer but every time I do reuse it I have to do
some additions/changes. It tested with up to hundred heavy duty threads
talking to web services, MS Access(!) be databases,  informing FE UI on
threads' status changes etc. - and FE is able to work for days without
restarting but that is a result of a very big work - it took two years+ to
get from first version to the current one. Of course I didn't program it for
two years, but getting all that experience to make it as it's now - that was
rather time consuming - at least for me...

If I ever will make that code less complicated I will share it but that will
not happen soon, sorry...

Thank you.

--
Shamil
 
-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: 10 ????? 2011 ?. 23:37
To: VBA
Subject: [dba-VB] c# - controlling the run state / status of your
threadedclasses

As I write classes that consume threads, I need to be able to start and stop
these threads and the class that consumes the threads.  For example, I open
a form and load a class instance that starts performing some process -
exporting sets of records to csv files for example.

Once that class is loaded and processing, I need to be able to ask that
class to stop exporting files.  However there may be a time lag between
asking and the currently processing file finishing it's export.  That is
precisely the purpose of a thread - tell it to go and do something else.

So (for example) I have a check box that I check that tells the class to
start exporting.  When it starts it sets a flag saying that it is running
and places text into the check box label saying that it is exporting (busy).

If I then uncheck the check box I am telling the class to stop exporting.
The class is monitoring the check box and will not process the next file but
it can't just exit.  So it needs to set a flag saying that it is stopping
and display "stopping" on the check box label.  When it finishes exporting
the file, it sets a stopped flag and says displays "terminated" in the check
box label.

So we have a couple of "commands" (start / stop) and a few statuses
(stopped, stopping, running).

I would like to "standardize" this into a class so that any class which
needs this interface does it in the same way.  Some controlling object can
tell the object to start and stop, and the class can tell the controlling
object that is is stopped, stopping or running.  this class does not6 need
to do any updating of labels or anything like that, just hold the variables,
properties, methods and code to perform this in a standard way.

Is anyone doing this?  Have existing code you would like to share?  Have
existing experience trying to do this you would like to share?

--
John W. Colby
www.ColbyConsulting.com
_______________________________________________
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