Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. Threading;
Using system;
Using system. Threading;
Namespace dataimportfromaccess
{
// Declare a callback function. Note that the passed parameters must be of the same type as the function parameters in the example class.
Public Delegate void examplecallback (INT linecount, label lb );
Public class form1 {
Public form1 ()
{
Initializecomponent ();
}
Public void currentnumber (INT tempcurrent, label lb)
{
LB. Text = tempcurrent. tostring ();
}
Private void button#click (Object sender, eventargs E)
{
Threadwithdata TWD = new threadwithdata (1,100, this. label1, new examplecallback (currentnumber ));
Thread TD = new thread (New threadstart (TWD. runmethod ));
TD. Start ();
}
Private void button2_click (Object sender, eventargs E)
{
Threadwithdata TWD = new threadwithdata (2,200, this. label2, new examplecallback (currentnumber ));
Thread TD = new thread (New threadstart (TWD. runmethod ));
TD. Start ();
}
}
Public class threadwithdata
{
Private int start = 0;
Private int end = 0;
Private examplecallback callback;
Private Label Lb;
Public threadwithdata (INT start, int end, label LB, examplecallback callback)
{
This. Start = start;
This. End = end;
This. Callback = callback;
This. lB = LB;
}
Public void runmethod ()
{
For (INT I = start; I <end; I ++)
{
Thread. Sleep (1000 );
If (callback! = NULL)
Callback (I, LB );
}
}
}
}