I am using circular progress bar NuGet for my application. My application reads a very big excel file, does some processing in the rows, and then does some other work. I am not sure how to set the maximum for my progress bar. At the moment, I have set it to the number of rows the application will process, but the issue with this approach is that the progress bar will show till the tool is processing the excel file and then it will close , though there are other processes that are being done after that also.
What I want –
Btn_click()
{
// show circular progress bar
//read input excel file
// process the rows
//do some more tasks
//close the circular progress bar
}
What I have done –
ProgressForm.cs (The circular progress bar form )
using System;
using System.Windows.Forms;
namespace ExcelChecker
{
public partial class ProgressForm : Form
{
public ProgressForm()
{
InitializeComponent();
}
public void UpdateProgress(int value)
{
if (InvokeRequired)
{
Invoke(new Action<int>(UpdateProgress), value);
}
else
{
circularProgressBar1.Value = value;
}
}
public void ShowProgress()
{
circularProgressBar1.Visible = true;
pictureBox1.Visible = true;
}
public void HideProgress()
{
circularProgressBar1.Visible = false;
pictureBox1.Visible = false;
}
}
}
Home.cs(The main screen)
private ProgressForm progressForm;
private void btnSubmit_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(filePath))
{
MessageBox.Show("Please select a file first.");
return;
}
progressForm = new ProgressForm();
progressForm.Show();
ProcessExcel(filePath);
}
private void ProcessExcel(string path)
{
//count rows of input excel file
progressForm.ShowProgress();
progressForm.circularProgressBar1.Maximum = rowCount - 1;
// read excel rows
progressForm.UpdateProgress(row - 1);
//process rows
progressForm.HideProgress();
//do something else
}