进度条不递增 [英] Progress Bar not incrementing

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

问题描述

我有以下的code的读取文件,也增加TE进度条读它,但我没有看到任何活动我的进度。任何人都可以请帮我,为什么?

  progressBar1.Minimum = 0;
progressBar1.Maximum =(int)的fileStream.Length + 1;
progressBar1.Value = 0;

使用(FILESTREAM)
{
    fileStreamLength =(int)的fileStream.Length + 1;
    fileInBytes =新的字节[fileStreamLength]
    INT currbyte = 0,I = 0;
    变种一个= 0;
    而(currbyte!= -1)
    {
        currbyte = fileStream.ReadByte();
        fileInBytes [我++] =(字节)currbyte;
        progressBar1.Value =我;

    }

 }
 

解决方案

据递增,但你不能看到它。它是通过在UI线程中运行你的循环引起的。 寻找BackgroundWorker的或异步/待机模式。

I have the following code which read a file and also increment te progress bar while reading it, but i dont see any activity in my progressBar. can anyone please help me why?

progressBar1.Minimum = 0;
progressBar1.Maximum = (int)fileStream.Length + 1;
progressBar1.Value = 0;

using (fileStream)
{
    fileStreamLength = (int)fileStream.Length + 1;
    fileInBytes = new byte[fileStreamLength];
    int currbyte = 0, i = 0;
    var a = 0;
    while (currbyte != -1)
    {
        currbyte = fileStream.ReadByte();
        fileInBytes[i++] = (byte)currbyte;
        progressBar1.Value=i;

    }

 }

解决方案

It is incrementing but you cannot see it. It is caused by running your loop in UI thread. Look for BackGroundWorker or async/await pattern.

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

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