在执行大循环时,进度条令人印象深刻 [英] Increamenting progress bar while execution of large loop

查看:61
本文介绍了在执行大循环时,进度条令人印象深刻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我几乎没有问题,可能会在使用Progressbar时遇到任何程序员,
让我们考虑以下场景,

Hi all,
I have little question that may get any programmer while using progressbar,
Lets consider following scenerio,

int j;
for(float i=0;i<1526974569745878;i++)
{
   SUM=SUM+i+j;
   j++;  
}


此循环可能需要6分钟才能执行.
所以我想执行相同的执行,但进度条不起作用.
在循环之后,进度条会像明智的那样增加.


This loop may get 6 minute to execute.
so i want do same execution With progress bar increament.
that after some looping a progress bar increase like wise.

NOTE:<br />
1)"1526974569745878" not constant may change time to time.<br />
2)I implemented this by using OnTimer() message handler but not working.<br />
Once execution enter in loop OnTimer() function is not called.<br />


______________________________________________________________________
所有链接,代码,帮助都是


______________________________________________________________________
ALL LINK,CODE,HELPS ARE WELCOME

推荐答案

m_progressInit.SetRange32( 0, PROGRESS_BAR_RANGE );
// PROGRESS_BAR_RANGE (Any Integer value)
if(i%1000 == 0)
{
   if(m_progressInit.GetPos() < PROGRESS_BAR_RANGE)
    {
        m_progressInit.StepIt( );
    }
    else
        m_progressInit.SetPos(0);
}


您必须为此使用单独的线程,
只需查看这篇完全模拟您的问题的多线程文章即可.

http: //www.codeguru.com/cpp/wp/system/threading/article.php/c16423/The-Practical-Guide-to-Multithreading---Part-1.htm [
You have to use separate thread for this,
Just check this Multithread article which exactly simulates your problem.

http://www.codeguru.com/cpp/w-p/system/threading/article.php/c16423/The-Practical-Guide-to-Multithreading---Part-1.htm[^].


如果这是在与其他任何代码相同的线程中完成的,则它将阻止发生其他任何事情.您应该重新考虑这样做,或者找出一种更好的方式来完成所需的工作(线程肯定是一种方式).
If this is done in the same thread as any other code, it''ll block out anything else from occurring. You should reconsider doing this or figure out a better way of accomplishing what you need (threading is definitely one way).


这篇关于在执行大循环时,进度条令人印象深刻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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