[英]How to run ProgressBar Form in new thread and manage it using C#?
I have simple form with progress bar: 我有带有进度栏的简单表格:
Like this: http://i.stack.imgur.com/jrM7Z.png 像这样: http : //i.stack.imgur.com/jrM7Z.png
I want start progress bar form before start hard method. 我要先启动进度栏表格,然后再启动硬方法。
For progress bar i need new thread. 对于进度条,我需要新的线程。
My code is: 我的代码是:
Thread myThread = new System.Threading.Thread(delegate () {
new ProgressBarForm().Visible = true;
});
myThread.Start();
hardMethodForAlongTime();
But if I run the code my progress bar lag and not working. 但是,如果我运行代码,进度条将滞后并且无法正常工作。
How can I do this? 我怎样才能做到这一点? And, can i stop thread using
myThread.Stop()
after hardMethodForAlongTime()
? 而且,我可以在
hardMethodForAlongTime()
之后使用myThread.Stop()
停止线程吗? Or is there any better solution? 还是有更好的解决方案?
Thread myThread = new System.Threading.Thread(delegate () {
new ProgressBarForm().Visible = true;
});
myThread.Start();
hardMethodForAlongTime();
myThread.Stop(); //stop?
Thank you for your replye. 感谢您的回覆。
For simplicity use BackgroundWorker. 为简单起见,请使用BackgroundWorker。 There is a lot of samples with BackgroundWorker and ProgressBar.
BackgroundWorker和ProgressBar有很多示例。 You can see this one C# BackgroundWorker
您可以看到这一个C#BackgroundWorker
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.