James Barash
James at fcidms.com
Tue May 15 08:52:19 CDT 2007
John: If you have the time here is a fairly thorough discussion of threading in VB.net with a set of classes (I know you like those) to facilitate exactly the type of threading you are trying to do. By the way, codeproject.com is an excellent resource for code samples for just about everything related to .Net. http://www.codeproject.com/vb/net/VBthreadingwrapper.asp If you want the quick and dirty approach: http://msdn2.microsoft.com/en-us/library/ywkkz4s1(VS.80).aspx Good luck. James Barash -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Tuesday, May 15, 2007 12:29 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VB.Net moving to a background worker thread I am using a clsProcessRawFiles that is the base unit for the transform process I wrote. Essentially it reads a directory to get a list of files to process, then opens a file, reads a line, transforms the line, and writes the line back out. The original method I used to do this was to dim the class and then call a method of the class to start the process of reading the files. The method call was in the click of a button. clsProcessRawFiles raises three events: evFilesToProcess (intFileCnt as integer). This event is fired after the method that reads the directory determines the file count, and allows the interface to set the total units for the main file progress bar. evCurrentFile (strFileName as string). This event allows the interface to display the file name being processed evFileComplete(intCnt as integer). This event essentially tells the main form how many files have been processed. As you can see, all of the file work is done in the method of the clsProcessRawFiles and progress events fire to allow the form to display the progress. I also have a cancel button that feeds a Boolean property of the class to allow the for loop processing the files to exit the loop if the cancel property is set. Mow... How do I move to using a worker thread? The events of course require the main form's thread to do the work of updating the various graphic elements that display progress - a progress bar and a text box for the file name. I assume that this is illegal if the class that is processing the files is on a worker thread? I want a thread to run the clsProcessRawFiles.mProcessFile method so that control is returned to the main form interface and the worker thread handles all of the file stuff. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com