Loop with threats in it

  • Thread starter Thread starter DraguVaso
  • Start date Start date
D

DraguVaso

Hi,

I want to perform this action in my application:
I gather all File-names in a directory, and than I want to do soem actiosn
with these Files (reading the records and puttign them in a Sql Server).

So my idea is: I perform a loop from the first until the last File. In the
loop I create a new isntance of a Class (clsImport or something liek that),
I gave that new isntance the name of the File, and than I want to have all
the actions done by this Class in a Thread.

So for not much problems. But I want to know when all the Threads are
finished (so when all the Files are imported). How can I know that every
Thread I started has ended? do I have to build my clsImport a specific way
to do this? Or do I have to to the threading a specific way?

Thanks a lot in advance,

Pieter
 
Hi

You can achive this using a callback method with the thread
clsImport
{
void ImportFile(string fileName)
{....}
}

public void delegate AsynchronDelegate( string fileName)
mainClass
{


then in the loop

clsImport cls =new clsImport();

//create a delegate for the importfile method
AsynchronDelegate dlgt=new AsynchronDelegate(cls.Import);

IAsyncResult ar=dlgt.BeginInvoke("myfile.txt",new
AsyncCallBack(fileFinished),dlgt);

//create method to call when process finishes
void fileFinished(IAsyncResult ar)
{
this method is called when it finishes;
}

}

Regards,

Dincer Uyav
 
Back
Top