进度栏扭曲问题 [英] Twisted progress bar problem

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

问题描述

我的问题有点扭曲...
如何 ?我的功能之一在执行复杂操作时将表单挂起
计算矩阵特征值和矩阵尺寸的计算方法不是恒定的,这妨碍了我预测进度条的最大值,虽然该函数进行计算,但也悬挂了表格,我想要的是,应该在显示进度条的同时函数终止时悬挂formvand,还必须设置进度条...
谢谢!

my problem is little bit twisted...
how ? one of my function hangs the form as it performs the complex
calculation of calculating eigen values of mattrix and dimension of mattrix is not constant which hinders me in predicting the maximum value for progress bar and while this function makes computation,it also hangs the form, what i want is that, progress bar should be displayed while hanging of formvand when function terminates ,progress bar must also be disposed...
Thank you!

推荐答案

它会挂起表单,因为所有处理都将进入计算功能-只有完成后才能更新GUI元素.您需要将缓慢的处理移至 BackgroundWorker线程 [
It hangs the form because all the processing is going to the calculation function - only when it finishes can the GUI elements get updated. You need to move teh slow processing into a BackgroundWorker thread[^] which means that the main form can be updated.

Do note that if you do display a progress bar from your BackgroundWorker, then you need to Invoke it as only the UI thread can access UI components!
private void ShowProgress(int percent)
    {
    if (InvokeRequired)
        {
        Invoke(new MethodInvoker(delegate { ShowProgress(percent); }));
        }
    else
        {
        myProgressBar.Value = percent;
        }
    }


我建​​议您使用此代码:
ProgressForm:链接到BackgroundWorker的简单表单 [
I suggest you use this:
ProgressForm: A simple form linked to a BackgroundWorker[^]


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

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