Tag: 进度条

使用后台工作程序 – 更新ProgressBar以了解递归方法的进度

下面是一个方法,我想发送到后台工作者,但我正在努力如何根据如何创建我的方法来做到这一点。 尽管如此,它不会返回任何正常的内容,但每次调用时都需要一个directoryInfo对象。 private void getSizeForTargetDirectory(DirectoryInfo dtar) { // generate a collection of objects. files comes first and then directories. foreach (Object item in collection ) { if (item == file) { track the size of the files as you encounter. } else if (item == directory) { // found a new directory, recall the method. […]

进度条前景色

有没有人知道如何更改WPF-Progressbar的前景色。 它似乎总是与绿色合并。

如何在繁忙循环期间显示进度?

我有一个循环,从外部源读取大量数据。 该过程大约需要20秒,我想向用户显示进度。 我不需要任何花哨的进度条,所以我选择在标签中绘制我的进度,该标签将显示“Step 1/1000”,然后更改为“Step 2/1000”等。 我的代码看起来像这样: // “count” is the number of steps in the loop, // I receive it in previous code String countLabel = “/”+count.ToString(); for (i = 0; i < count; i++) { … do analysis … labelProgress.Content = "Step "+i.ToString()+countLabel } 但是,在该分析期间,屏幕“卡住”并且进度未显示为前进。 我从过去的C ++中理解这种行为,我可能会有一个单独的线程,显示进度条接收来自循环的通知,或某种forms的重绘/刷新,或强制窗口/应用程序处理其消息队列。 在C#中使用它的正确方法是什么? 我没有绑定标签,所以如果有一个简单的进度条弹出屏幕我可以使用而不是这个标签它也会很棒…… 谢谢

在BackGroundWorker中运行方法并显示ProgressBar

我想要的是当一些方法正在做一些任务时UI保持活跃,我想在进度条中显示工作的进度。 我有一个方法,一个BackGroundWorker和一个Progressbar 。 我想在BackGroundWorker开始运行时调用该方法并显示进度。 该方法包含一个循环。 因此,它可以报告进度。 那么,可以做些什么呢? private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the ‘dataSet1.TBLMARKET’ table. You can move, or remove it, as needed. myBGWorker.WorkerReportsProgress = true; } private void myBGWorker_DoWork(object sender, DoWorkEventArgs e) { parseFiles(); } private void myBGWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { myProgressBar.Value […]

C#Winform ProgressBar和BackgroundWorker

我有以下问题: 我有一个名为MainForm的表单。 我要在这张表格上进行长时间的操作。 虽然这个长时间的操作正在进行,但我需要在MainForm之上显示另一个名为ProgressForm的操作。 ProgressForm包含一个进度条,需要在长时间操作时更新。 长操作完成后,应自动关闭ProgressForm。 我写了以下代码: using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Threading; namespace ClassLibrary { public class MyClass { public static string LongOperation() { Thread.Sleep(new TimeSpan(0,0,30)); return “HelloWorld”; } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace BackgroungWorker__HelloWorld { public partial […]

使用进度条下载异步文件

随着WebClient下载进度的变化,我试图让进度条的进度发生变化。 这个代码仍然下载文件,当我调用startDownload() ,窗口会在下载文件时冻结。 我希望用户能够在启动屏幕加载时看到进度更改。 有没有办法解决这个问题,以便用户可以看到progressBar2的progressBar2发生变化? private void startDownload() { WebClient client = new WebClient(); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted); client.DownloadFileAsync(new Uri(“http://joshua-ferrara.com/luahelper/lua.syn”), @”C:\LUAHelper\Syntax Files\lua.syn”); } void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { double bytesIn = double.Parse(e.BytesReceived.ToString()); double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); double percentage = bytesIn / totalBytes * 100; label2.Text = “Downloaded ” + e.BytesReceived […]