使用线程时,桂freeezing [英] Gui freeezing when using threading

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

问题描述

我卡住,希望有人能帮助我。

I am stuck and was hoping someone could help me.

我已经设置为滚动字幕,这样,当一个任务正在紧张进行中,我可以把它显示给用户加载条的类/ GUI。

I have made a class/gui with a loading bar set to marquee so that when a task is being carried out i could display it to the user.

在我的GUI类之一,在第一行的构造我在写这个类的一个新实例,然后做

In one of my gui classes, in the constructor on the first line i am making a new instance of this class and then doing

    LoadingBar bar = new LoadingBar();
    Thread thread = new Thread(bar.Show);
    thread.Start();



然而,即使寿主程序线程会关闭做一些更深入的东西,这个GUI似乎仍冻结,即使我使用底色的工人。

However, even tho the main programme thread is going off doing some more intensive stuff, this gui still seems to freeze, even if i use backround worker.

时有什么错我刚才提到的方法,如果是这样,我需要改变什么?

Is there anything wrong with the approach i have mentioned and if so what do i need to change?

感谢

推荐答案

您需要扭转你的方法。图形用户界面需要留在主线程同时工作在一个工作线程(通常是一个BackgroundWorker)来完成。然后,工作人员报告回到GUI,然后更新。

You need to reverse your method. The GUI needs to stay in the main thread while the work is done in a "worker thread" (typically a BackGroundWorker). Then the worker reports back to the GUI which then updates.

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

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