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 partial class Form1: Form
{
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 );
}
}
}
}