[英]BackgroundWorker in VS2010 doesn't run in another thread
I created a WinForm in Visual Studio 2010 (c++), almost the same as this example: http://msdn.microsoft.com/en-us/library/waw3xexc.aspx 我在Visual Studio 2010(c ++)中创建了一个WinForm,几乎与此示例相同: http : //msdn.microsoft.com/zh-cn/library/waw3xexc.aspx
but when I click on the button that "lunch" the BackgroundWorker it "stucks" the WinForm, so I can't move it or click on "stop button" for the time the function runs. 但是,当我单击“插入” BackgroundWorker的按钮时,它“粘住”了WinForm,因此我无法移动它或在函数运行时单击“停止按钮”。
The function runs as desired - is returns the expected result, and also the progress bar is ok. 该函数按预期运行-返回预期结果,进度条也正常。 It seems that the BackgroundWorker runs in the same thread as the WinForm. 似乎BackgroundWorker与WinForm在同一线程中运行。
What might be the problem? 可能是什么问题?
Thanks! 谢谢!
I found the problem. 我发现了问题。
The BackgroundWorker actually runs on another thread but it send Events of update progress too often and those events "lunch" function in the main form - that updates ProgressBar - and this funcion "stucks" the form. BackgroundWorker实际上在另一个线程上运行,但是它发送更新进度的事件过于频繁,并且那些事件在主窗体中“午餐”功能(更新ProgressBar),并且此函数“阻塞”了窗体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.