进度条C# [英] Progress Bar C#

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

问题描述

我有一个进度条,显示程序加载歌曲到库的状态。

I have a progress bar to show the status of the program loading songs into the library.

    foreach (Song s in InitializeLibrary())
    {
        Library.AddSong(s);
        pBar.Value++;
        pBar.Update();
    }



InitializeLibrary()仅仅是返回一个列表

InitializeLibrary() is just a function that returns a List

的问题是,在进度条停止移动的某一点后(如20%),而值仍增加。有没有一种方法,使之更新的100%的时间?

The problem is that the progress bar stops "moving" after a certain point (eg 20%), while the value still increases. Is there a way to make it update 100% of the time?

推荐答案

我这样做的方法是使用< A HREF =htt​​p://msdn.microsoft.com/en-us/library/8xs8549b%28VS.80%29.aspx> BackgroundWorker组件。

The way I have done this is by using a BackgroundWorker component.

使用它加载在后台线程上的歌曲和报告给UI线程,将更新进度条的进展。

Use it to load your songs on a background thread and report progress to the UI thread that will update your progress bar.

在后台工作处理所有的消息传送对于正在进行的报告线程之间。

The background worker handles all of the messaging between threads for the reporting of progress.

这让你多线程的好处,而无需管理线程自己。

This gets you the benefits of Multithreading without having to manage the threading yourself.

有一个很好的教程将介绍如何使用进度的报告是这里

A good tutorial that will show how to use the progress reporting is here.

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

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