【发布时间】:2017-11-23 08:19:09
【问题描述】:
我目前正在处理一个需要处理大量数据的项目,因此我决定创建一个 Windows 窗体,通知用户正在进行处理。当然,我必须使用另一个线程。但是我需要多次运行这个窗口(不是同时,但它第一次启动良好,第二次启动不好),我必须有一个启动线程的方法和另一个停止它的方法以及一个标签将根据在另一个线程中的方法中执行的循环次数显示不同的内容(这很棘手^^)。
我读了很多关于线程的文章,但我仍然没有找到如何去做。 我做的一些代码:
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();
}
我想使用类似的东西,我该怎么做?
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;
}
}
谢谢。
【问题讨论】:
标签: c# multithreading