新形式是新线程吗? [英] Is new form mean new thread ?

查看:103
本文介绍了新形式是新线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,对C#来说很陌生(你甚至可以说最终是C#的新手)

我正在编写程序并偶然发现性能问题。



我有两个表格,我的问题是第二个表格。它包含大约960个控件(完全按钮),当它被调用时,它需要超过5分钟才能显示。



和互联网上的seraches后我发现在一个窗口中放置大量控件是错误的。



so如果把它分开,说四种不同的形式并且应该单独调用,这会解决我的问题吗?或者我可以使表单加载器工作多线程吗?



谢谢

I'm new,very new to C# (you can even say ultimately new to C#)
i'm writing a program and stumbled upon performance problem.

I have two form,my problem is the 2nd form.It's contain about 960 controls (button exactly) and when it's called it took more than 5 minutes to show up.

and after seraches on the internet i found that it's wrong to put a massive amount of control in one window is wrong.

so if divide it,say to four diffrent form and should called separately,will this resolve my problem ? or can i make the Form loader work multi-threaded ?

Thankyou

推荐答案

你不能解决这个问题。所有控件及其创建必须在UI(有时称为启动)线程上。



您可以在不同的线程上创建控件,甚至可能出现大部分时间工作。但是如果你这样做的话,你会在使用应用程序时得到最奇怪,不可再现的错误。



不仅仅在1个表单上有960个按钮,这不是一个好习惯,但同时在屏幕上以任意数量的形式!用户如何通过这一大堆控件找到他们想要点击的那个???



这听起来像你正在尝试使用按钮作为表格上的图像的一些表示,也许是游戏,你不知道除了使用按钮之外还有什么其他的东西。



哦,并且单独的表单并不意味着单独的线程。所有表单都将在同一个执行线程上。
You cannot thread this. All controls and their creation must be on the UI (sometimes referred to as the "startup") thread.

You can create controls on different threads and they may even appear to work, most of the time. But you will get the weirdest, unreproducable bugs when using the application if you do.

It is simply not a good practice to have 960 buttons not only on 1 form, but in any number of forms on screen at the same time! How is the user going to navigate through this massive pile of controls to find the one they are trying to click on??

This sounds like you're trying to use buttons as some representation of an image on a form, perhaps a game, and you don't know how else to do something other than use a button.

Oh, and a separate form does NOT mean a separate thread. All forms will be on the same thread of execution.


在标题,线程和表单中回答特定问题是两回事。 C#在原始意义上不是真正的编译器。 C#编译到一个未编译为native的中间形式。代码直到运行时。性能问题可能来自运行时的JIT编译。一个更简单的表单可能会更快地编译和显示。可能还有其他问题。
Answering the specific question in the title, thread and form are two different things. C# is not a real compiler in the original sense. C# "compiles" to an intermediate form which is not compiled to "native?" code until runtime. The performance problem probably comes from the JIT compile at runtime. A simpler form will probably compile and display faster. There may be other issues.


这篇关于新形式是新线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆