如何始终在单独的线程上运行控件及其所有子控件?
我编写了一个应用程序,它对巨大的浮点数进行大量计算,这使得 UI 在大多数时间都没有响应。
我正在考虑向该应用程序添加一个状态栏,并显示一些有关 cpu 负载、已用内存和进度条的信息。考虑将标签和进度栏作为子项添加到状态栏,如何在单独的线程上运行此状态栏,该线程可以可靠地尽可能地响应?
我已经可以正常使用进度条和系统诊断工具了。我正在寻找的是您的想法和技巧,可能还有一些代码!
更新
我希望状态栏显示实时CPU和内存详细信息。如何解决这个问题?
I have written an application which does lots of calculation on huge floating point numbers that makes the UI not responsive at all most of the time.
I am thinking of adding a status bar to this application and show some info about cpu load, used memory and a progress bar. Consider adding labels and progress bar to the statusbar as childs, how can I run this status bar on a separate thread which can be reliable to be responsive as much as possible?
I can already use progress bars and system diagnosting stuff normally. What I am looking for is your ideas and tips, possibly with some codes!
Update
I want the status bar shows real time cpu and memory details. How to workaround this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你把这件事搞错了。您应该在同一个线程中运行所有 UI,并在后台工作程序中运行长计算。尝试在同一个应用程序的不同线程中运行 UI 只会带来痛苦。
You've got this the wrong way round. You should run all the UI in the same thread, and run the long calculation in a background worker. Trying to run UI in different threads within the same app just leads to pain.
最好的办法就是在 Google 上搜索 BackgroundWorker。这是关于如何使用它的一个特定结果。
http://midnightprogrammer.net/post/Using-Background-Worker-in -C.aspx
Best thing is to just do a google search on BackgroundWorker. Here is one particular result on how to use it.
http://midnightprogrammer.net/post/Using-Background-Worker-in-C.aspx