线程Windows窗体 [英] Thread for Windows form

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

问题描述

当我创建一个简单的Windows形式,它在一个新的线程会自动启动?或者有各种形式的只能有一个线程?

When I'm creating a simple Windows form, is it starting in a new thread automatically? Or there is only one thread for all forms?

推荐答案

有适用于所有形式的一个线程。

There is one thread for all forms.

在事实上,Windows窗体(和大多数窗口技术),要求您的所有窗体和控件在单个线程产生。如果您尝试从不同的线程使用控制,就会造成问题。

In fact, Windows Forms (and most windowing technologies), require that all of your forms and controls be generated on a single thread. If you try to use a control from a different thread, it will cause a problem.

在Windows应用程序的UI线程实际上花费大多数时间在闲置。有被处理的消息队列,和这将导致待提高你处理的事件。如果你想从另一个线程访问UI,你必须(使用Control.Invoke)要回跑进UI的线程的方法,或者您会收到异常调用。

The UI thread in a Windows application actually spends most of its time idle. There is a message queue that is processed, and which causes the events you handle to be raised. If you want to access the UI from another thread, you have to invoke (using Control.Invoke) the method you want to run back onto the UI's thread, or you will receive exceptions.

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

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