有关进度条的问题

yuyu46569 2010-09-11 11:48:08
我有个进行算法的程序,在算的过程中有用到进度条。当进行算小数据(几分钟就能算完的那种)的时候进度条是可以正常动的。 当算一种要4个多小时才能算完的数据,进度条就不动了 这是何解?
...全文
124 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kensouterry 2010-09-11
  • 打赏
  • 举报
回复
Designer代码

namespace WindowsFormsApplication1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(146, 139);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(324, 23);
this.progressBar1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(271, 229);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(652, 420);
this.Controls.Add(this.button1);
this.Controls.Add(this.progressBar1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.ProgressBar progressBar1;
private System.ComponentModel.BackgroundWorker backgroundWorker1;
private System.Windows.Forms.Button button1;

}
}


kensouterry 2010-09-11
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
//Remember to add a reference---
using Microsoft.Office.Interop.Word;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
delegate void DisplayValueDele(object o,int progress);
DisplayValueDele displayValueExecute;

public Form1()
{
InitializeComponent();

displayValueExecute = new DisplayValueDele(DisplayValueExecute);


}

public void DisplayValueExecute(object o,int progress)
{
ProgressBar pb1 = (ProgressBar)o;
if (pb1.InvokeRequired)
{
IAsyncResult ar=this.BeginInvoke(displayValueExecute, new object[2] { pb1,progress });
this.EndInvoke(ar);
}
else
{
progressBar1.Value = progress;
}
}

private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 101; i++)
{
displayValueExecute(progressBar1, i);
Thread.Sleep(50);
}

}


}
}


建议使用BackgroundWorker控件,因为那控件很好控制一个新开的线程。有不懂的参考MSDN
jointan 2010-09-11
  • 打赏
  • 举报
回复
操作进度条后调用一下窗口的Update方法和Application.DoEvents方法试试

我也有一个软件有这种毛病,单线程的,在单核处理器上没问题,在单核双CPU系统上也没问题,在多核处理器上,和你描述的情况差不多,现在原码不在手上,当时调没调用窗口的Update方法和Application.DoEvents方法我忘记了
yuyu46569 2010-09-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lockepeak 的回复:]
把step设大些
[/Quote]
我设的是100
lockepeak 2010-09-11
  • 打赏
  • 举报
回复
判断 设不同的 步进值
lockepeak 2010-09-11
  • 打赏
  • 举报
回复
把step设大些
兔子-顾问 2010-09-11
  • 打赏
  • 举报
回复
描述的不清晰。会不会是进度条的max太大了。改变会很缓慢。尝试放2个进度条。一个表示某一次循环的小操作,另一个表示总的进度,有一个会很快,另一个慢一点。

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧