后台线程与 UI 线程
任何人都可以帮我找出 C# 中的后台线程和 UI 线程吗?我已经用 google 搜索了它,但我找不到说明这两者的文章。
Could any one help me to figure out background thread and UI thread in C#.I have googled it but i coudnt find article illustrate both.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UI 线程创建 UI 元素并等待和响应鼠标单击和按键等事件。您只能从 UI 线程访问 UI 元素。
有两种类型的线程:后台线程和前台线程。 UI 线程是前台线程的一个示例。
后台线程和前台线程之间的区别非常简单。后台线程不会阻止进程终止,但前台线程可以。当最后一个前台线程停止时,所有后台线程也停止,进程结束。
A UI thread creates UI elements and waits and responds to events like mouse clicks and key presses. You can only access the UI elements from the UI thread.
There are two types of threads: background and foreground. A UI thread is an example of a foreground thread.
The difference between background and foreground threads is pretty simple. Background threads don't stop a process from terminating, but foreground threads do. When the last foreground thread stops, then all the background threads are also stopped and the process ends.
该网站提供了大量有关线程以及并行编程的信息:http://www.albahari.com/threading /
祝你好运
This website has a lot of information about threading as well as parallel programming: http://www.albahari.com/threading/
Good luck
还有另一个关键问题需要记住。有一个 UI 线程,您只能调用该线程中 UI 对象的方法。在另一个线程中,如果您正在执行更新状态栏之类的操作,则需要调用 Control.Invoke() 来切换到 UI 线程。
There is another key issue to keep in mind. There is a single U.I. thread and you can only call methods on U.I. objects in that thread. In another thread you need to call Control.Invoke() to flip to the U.I. thread if you are doing something like update a status bar.