持续进度条 [英] Continuous progressbar

查看:82
本文介绍了持续进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在从Windows窗体"FormA"调用一个方法。该方法命名为"Method1()"。可用于另一个类别"ClassA"。


此"FormA"包含名为"lblStatus"的标签和一个进度条如


progressbar.Style = ProgressBarStyle.Marquee;


progressbar.MarqueeAnimationSpeed = 30;


在调用"Method1()"之前,进度条连续运行。但是,当我称之为方法"Method1()"时,进度条停止运行。


" lblStatus"用于"ClassA"中。向用户说出状态。


我的目标是使进度条运行,即使在"FormA"中也是如此。调用方法"Method1"来自"ClassA"。


有人可以帮助我吗?


提前致谢。



解决方案

它似乎阻止了用户界面线程。


默认情况下,表单应用程序有一个用户界面线程,这意味着当你从事件处理程序运行代码时,GUI停止响应。


你有几个选项可以解决这个问题:


(1)使用.NET 4.5中的酷异步方法功能


(2)确保Method1在自己的线程中运行不要阻止GUI线程。


(3)从Method1调用Application.DoEvents(),特别是在循环代码中。



Hi,

I am calling a method from a windows form "FormA". That method named "Method1()" is available in another class "ClassA".

This "FormA" contains a label named "lblStatus" and a progressbar like

progressbar.Style = ProgressBarStyle.Marquee;

progressbar.MarqueeAnimationSpeed = 30;

Before calling "Method1()", progressbar runs continuously. But when I call that method "Method1()" the progressbar stops running.

"lblStatus" is used in "ClassA" to say the status to the user.

My objective is to make the progressbar running even when the"FormA" calls the method "Method1" from "ClassA".

Could anyone help me in this?

Thanks in advance.

解决方案

Its seems you are blocking the user interface thread.

By default, Form applications have a single user interface thread, which means that when you run code from an event handler the GUI stops responding.

You have several options to fix this:

(1) Use the cool async methods feature in .NET 4.5

(2) make sure Method1 runs in its own thread as not to block the GUI thread.

(3) Call Application.DoEvents() from Method1, especially in loop code.


这篇关于持续进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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