Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a progress bar in windows forms C#?
    primarykey
    data
    text
    <p>I have my own solution to import monthly sales data in my windows form application. When a user click on <code>import</code> button, the program is actually running but it looks like it's not responding. The process takes a long time about 5 minutes.</p> <p>So, I'd like to implement a progress bar with status strip label to display as an user interface and let the users know how much the task is done. This is also my first time using a progress bar in my program. So, I read through some tutorials which show how to use it. Some people use progress bar with background worker and timer. </p> <p>But I don't understand where I should use the solution that I have. In background worker <code>DoWork()</code> event? I don't want to fake it by abusing the progress bar like setting the progressBar.Maximum = 100, progressBar.Value = 0 and as long as the timer is ticking increasing the value by 5. The progress bar must report the actual progress while the program is running.</p> <p>The following is the solution I am using now to import the data:</p> <pre><code>private void btnImport_Click(object sender, EventArgs e) { if (lsbxBrowsedFiles.Items.Count != 0) { ArrayList salesHeaderArr = new ArrayList(); ArrayList salesDetailArr = new ArrayList(); int i = 0; while (i &lt; browsedXmlFileList.Count) { if (browsedXmlFileList[i].ToUpper().EndsWith("SALESHEADER.XML")) { salesHeaderArr.Add(browsedXmlFileList[i]); } if (browsedXmlFileList[i].ToUpper().EndsWith("SALESDETAIL.XML")) { salesDetailArr.Add(browsedXmlFileList[i]); } i++; } if (selectedFileIsNotInDestinationFolder(salesHeaderArr, salesDetailArr) == true) { i = 0; while (i &lt; salesHeaderArr.Count) { SalesHeader salesHeader = new SalesHeader(); string sourceFilePath = salesHeaderArr[i].ToString(); readXMLFiles(sourceFilePath, SALES_HEADER); SalesHeader salesCheck = (SalesHeader)salesHeaderList[0]; string checkOutletCode = salesCheck.OutletCode; DateTime checkBusDate = salesCheck.BusinessDate.Value; if (SalesHeader.IsThisRowAlreadyImportedInSalesHeader(checkOutletCode, checkBusDate) == false) { salesHeader.ImportSalesHeader(salesHeaderList); salesHeader.CreateImportDataLog(getDestinationFilePath(sourceFilePath), DateTime.Now, salesHeaderList.Count, SALES_HEADER); } else { string errorDate = checkBusDate.ToString("dd MMMM, yyyy"); MessageBox.Show("Selected XML File with BusinessDate: " + errorDate + " has been already imported.", "ABC Cafe Import Sales Wizard"); MessageBox.Show("Please select a file which has not been imported!", "ABC Cafe Import Sales Wizard"); return; } MoveXMLFiletoDestinationFolder(sourceFilePath); i++; } i = 0; while (i &lt; salesDetailArr.Count) { SalesDetail salesDetail = new SalesDetail(); string sourceFilePath = salesDetailArr[i].ToString(); readXMLFiles(sourceFilePath, SALES_DETAIL); SalesDetail salesCheck = (SalesDetail)salesDetailList[0]; string checkOutletCode = salesCheck.OutletCode; DateTime checkBusDate = salesCheck.BusinessDate.Value; if (SalesDetail.IsThisRowAlreadyImportedInSalesDetail(checkOutletCode, checkBusDate) == false) { salesDetail.ImportSalesDetail(salesDetailList); salesDetail.GenerateCarryForward(salesDetailList); salesDetail.CalculateImportInventoryBalance(salesDetailList); salesDetail.CreateImportDataLog(getDestinationFilePath(sourceFilePath), DateTime.Now, salesDetailList.Count, SALES_DETAIL); } else { string errorDate = checkBusDate.ToString("dd MMMM, yyyy"); MessageBox.Show("Selected XML File with BusinessDate: " + errorDate + " has been already imported.", "ABC Cafe Import Sales Wizard"); MessageBox.Show("Please select a file which has not been imported!", "ABC Cafe Import Sales Wizard"); return; } MoveXMLFiletoDestinationFolder(sourceFilePath); i++; } MessageBox.Show("Import has been successfully completed!", "ABC Cafe Import Sales Wizard"); clearListBoxItems(); lblMessage.Visible = false; } //Abort the import operation here! else { MessageBox.Show("Please select a file which has not been imported!", "ABC Cafe Import Sales Wizard"); clearListBoxItems(); lblMessage.Visible = false; } } else { MessageBox.Show("Please select XML files to import!", "ABC Cafe Import Sales Wizard"); } } </code></pre> <p>Any help will be very much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload