简体   繁体   English

读取MPP文件时如何运行进度栏?

[英]How to Run Progress Bar While Reading a MPP File?

I'm trying to have a progress bar running while reading a file. 我正在尝试在读取文件时运行进度条。 I'm not sure how to do this. 我不确定该怎么做。 Help is much appreciated. 非常感谢您的帮助。 Code is below: 代码如下:

 UploadProgressBar.Visible = true; 
 UploadProgressBar.Value = 0;
 CurrentFile = reader.read(CurrentFileName); //need progress bar running during this code
 UploadProgressBar.Value = 100;
 UploadProgressBar.Visible = false;
 CurrentFileLabel.Text = CurrentFileName;

You have to execute your reading operation in another thread, because in this way you're blocking the UI thread. 您必须在另一个线程中执行读取操作,因为这样会阻塞UI线程。

So 2 options here : 所以这里有2个选择:

  1. Keep your current setup that seems working for you 保留当前适合您的设置
  2. Launch your operation on another thread : 在另一个线程上启动操作:
    await Task.Run(async() => CurrentFile = reader.read(CurrentFileName));

The problem here is that if your read() doesn't have a callback to inform you about the progress you'll not be able to update the progress par accordingly to the operation progress. 这里的问题是,如果您的read()没有回调通知您进度,则您将无法根据操作进度更新进度参数。 It would probably be an easier option to implement an infinite progress bar here. 在这里实现无限进度条可能是一个更容易的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM