I am currently working on a project that requires processing a lot of data, so I decided to create a windows form informing the user that the processing is in progress. Of course I have to use another thread. But I need to run this windows form several times (not at the same time but it starts well the first time and not well the second), I must have a method that starts the thread and another that stops it as well as a label that will display different things depending on the number of loop perform in a method that is in another thread (it's tricky^^).
I read a lot about threads but I still have not found how to do it. Some code I did :
public partial class Progress : Form
{
Thread thr = null;
public Progress()
{
InitializeComponent();
try
{
thr = new Thread(() => this.ShowDialog());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void Start()
{
thr.Start();
//this.ShowDialog();
}
public void Stop()
{
thr.Abort();
thr.Join();
//this.Close();
}
and i want to use something liked that, How can I do it ?
other class {
Progress t = new Progress();
t.Start();
firstFunction();
SecondBigFunction(t);
threeFunction();
t.Stop();
}
SecondBigFunction(Thread t){
while(list.lenght > 0){
// Do somework
t.labelToChange += 1;
}
}
Thank you.