使用ThreadPool添加多个Picturebox
我正在为大学参加一场海战。我决定用 C# 来做。我的板是 20 x 20 的迷你 (20x20) 图片框。问题是,当我加载板子时,在包含它们的面板中绘制所有板子时出现了巨大的延迟。所以我想到了 ThreadPool 我的方法来扩展图片框的创建和绘图溃烂。
这是正确的方法吗?我想知道即使我启动 20 个线程来创建并将图片框设置在一起,我是否仍然会有图形延迟。
(我现在不会过去代码,因为也许答案与它无关......如果没有,我接下来会过去:)
抱歉英语不好,
谢谢大家!
Im doing a Naval Battle for University. I decided to do it in C#. My board is 20 x 20 of mini (20x20) PictureBoxes. The problem is when I load the board I got a huuuge delay for draw all of them in the panel which contains them. So I thought to ThreadPool my method to escale the picuteres boxes creation and drawing fester.
Is this the correct aproach? I'm wondering if even if I launch 20 threads to create and set the picturesoboxes together I will still have the graphic delay.
(I wont past code right now because maybe the answer independs of it... if not, I past next :)
Sorry the bad english,
Thanks folks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基本上这不太好,因为您不应该从主线程旁边的其他线程更改 UI。这样做会导致不当行为。您可以检查加载图片的代码,可能可以改进它或者只是考虑不同的实现。
Basically this would not be very ok because you should not change the UI from other threads beside the main one. Doing that would result in improper behaviour. You could check the code where you load the pictures, probably it can be improved or just think of a different implementation.
看一下 codeproject 中的 2 个示例项目:
Take a look at 2 sample projects from codeproject:
也许在内存中构建单个位图(您可以将小的位图绘制到位图表示的图形对象上),然后显示该单个位图。
(用这个方法也看看双缓冲)
Perhaps construct a single bitmap in memory (you can draw the small ones onto the graphics object the bitmap represents) then display the single bitmap.
(with this method look at double buffering also)